power BI 所有批准列计数

power BI All approve columns counts

我有这些数据

create table #data (MilesID INT, Milestone varchar(50), Sataus varchar(50))
insert into #data values

(101 ,'Done All 20','A-approved completed'), (101 ,'Done All 20','CA-approved completed'),
(101 ,'Done All 20','DC-approved completed'), (102 ,'well done 25','QA-approved Done'),
(102 ,'well done 25','DV-approved Accept'), (103 ,'Done 18','Incomplete'),
(103 ,'Done 18','CA-approved completed'), (103 ,'Done 18','DC-approved completed'),
(104 ,'Late 3','Awaiting'),(104 ,'Late 3','DC-approved completed')
select
*
from #data
drop table #data

我希望能够检查 MilesID 是否相同,并且状态包含已批准的相同 MilesID 我想将其计为 1。例如。 MilesID 101和102的status都包含Approved,但是103和104不是,因为所有status都不包含approved

我厌倦了这个 DAX

 Measure = 
CALCULATE(DISTINCTCOUNT(Data[MilesID]),     
   FILTER(Data,if(CONTAINSSTRING(Data[Status],
    "approved")=TRUE(),"approved",BLANK())<> BLANK() ))

输出为4 但我想要的结果应该是 2

我也试过了

FinalCheck = var one =COUNT(Data[MilesID])
             var two= CALCULATE(COUNT(Data[Status]),
             FILTER(Data,CONTAINSSTRING(Data[Status],"approved")=TRUE()))
              var three= IF(one - two =0,1,0)
              return
              three

这个returns 0 个作为答案

请试试这个:

Measure = DISTINCTCOUNT(Data[MilesID]) - CALCULATE(DISTINCTCOUNT(Data[MilesID]), NOT(CONTAINSSTRING(Data[Status],"approved")))

找到答案的三个步骤:

  1. 查找此数据中有多少个不同的 MilesID table。
  2. 找出有多少不同的 MilesID 状态不包含“已批准”
  3. 第 1 步 - 第 2 步