Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I need a Dax that count the Names distinctly that has the Flag=1 but don´t has the Flag=0
In SQL I could do something like this:
Select count(distinct Name) Qtd from Table1 A where Flag = 1 and not exists (select 1 from Table1 B where A.Name = B.Name and A.Flag =0) |
Qtd Names With flag 1 but not 0 = ?
Name | Flag |
Joao | 1 |
Joao | 0 |
Andre | 1 |
Mateus | 0 |
The result espected is just Andre, beucause he is the only that has the flag 1 and hasn´t the 0
Name | Flag |
Andre | 1 |
Hi @souzacaleb,
Here’s my sample data:
Please check following steps as below:
1. Create calculated columns:
Column =
var a = CALCULATE(COUNTROWS('table'),FILTER('table','table'[Name] = EARLIER('table'[Name])))
var b = CALCULATE(COUNTROWS('table'),FILTER('table','table'[Name] = EARLIER('table'[Name])&&'table'[Flag] = 1))
return
a=b
2. Create measure:
Measure = CALCULATE(DISTINCTCOUNT('table'[Name]),FILTER('table','table'[Column] = TRUE()))
3. Result would be shown as below:
Best Regards,
Jay
Community Support Team _ Jay Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-jayw-msft
Is there any way achieve the same result without create the columns step? Is it possible to do all in a measure?
I aprecciate for you help.
@Anonymous
small change on the sql query.
select distinct a.Name
from FlagTable a
where a.Flag=1
and not exists(select 1 from FlagTable b where b.Flag=0 and a.Name=b.Name)
we will expect someone need to help with DAX.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
106 | |
88 | |
75 | |
66 |
User | Count |
---|---|
125 | |
114 | |
98 | |
81 | |
73 |