Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreThe FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now
I am trying to write DAX formula with following logic:
Count distinct "ClientID" if one has "Refused" in Consent column,
BUT, if one has "Consented" in Consent column, do not count (exclude) distinct "ClientID".
So, client 69 and 12468 should be excluded from counting.
This is my original DAX:
Refused = CALCULATE (
Refused = CALCULATE (
)
)
I don't think it works.
I need to find the way to calculate the count ClientID level, not table level.
Solved! Go to Solution.
Ok, thanks for clarifying.
Refused Not Consented =
VAR Refused =
DISTINCT (
SUMMARIZE (
FILTER ( 'Table', 'Table'[Consent] = "Refused" ),
'Table'[ClientID]
)
)
VAR Consented =
DISTINCT (
SUMMARIZE (
FILTER ( 'Table', 'Table'[Consent] = "Consented" ),
'Table'[ClientID]
)
)
RETURN
COUNTROWS ( EXCEPT ( Refused, Consented ) )Regards
Ok, thanks for clarifying.
Refused Not Consented =
VAR Refused =
DISTINCT (
SUMMARIZE (
FILTER ( 'Table', 'Table'[Consent] = "Refused" ),
'Table'[ClientID]
)
)
VAR Consented =
DISTINCT (
SUMMARIZE (
FILTER ( 'Table', 'Table'[Consent] = "Consented" ),
'Table'[ClientID]
)
)
RETURN
COUNTROWS ( EXCEPT ( Refused, Consented ) )Regards
@Jos_Woolley Thank you for your help. I am trying to understand the logic here. First, we are counting all rows that have a word "Refused". Then, we are also counting all rows that have a word "Consented". Is it right? Then, what does the rest of statement mean? I think I understand what 'Except' means, but from what dataset (from all criteria - including others ('Historial', 'Not Eligible', etc.)? Or am I totally off the track? Thank you.
The first part:
VAR Refused =
DISTINCT (
SUMMARIZE (
FILTER ( 'Table', 'Table'[Consent] = "Refused" ),
'Table'[ClientID]
)
)defines the variable 'Refused' as the single-column table comprising the distinct values from the ClientID column for which the Consent column entry is "Refused".
The next variable is similarly defined, though for Consent column entries of "Consented".
The EXCEPT clause then returns a single-column table comprising all Client ID entries from the 'Refused' table which do not appear in the 'Consent' table.
Finally, the number of rows in this last table are counted.
Regards
@Jos_Woolley Thank you for your explanation. Now I understand what 'Except' does in DAX.
You're welcome!
Regards
Hi,
In the example you give, the only two possible entries in the 'Consent' column are 'Consented' and 'Refused'. As such, you can use:
Refused =
DISTINCTCOUNT ( 'Table'[ClientID] )
- CALCULATE (
DISTINCTCOUNT ( 'Table'[ClientID] ),
'Table'[Consent] = "Consented"
)If other entries are in fact possible within the 'Consent' column then please update your post with a more realistic dataset.
Regards
@Jos_Woolley Sorry. actually, there are different options for the value in the "Consent" column (like 'Historial', 'Not Eligible').
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 14 | |
| 11 | |
| 6 | |
| 5 |