Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi all
I am trying to do a countdistinct dax to multiple columns.
The logic is: count me the unique values for the columns Code and the column Attribute for the value attribute 1.
The dax I used is:
count rows distinct = COUNTROWS(FILTER(GROUPBY(Test111, Test111[Code]), Test111[Attribute] = "Attribute 1"))
I must have a syntax problem because is not recognizing me the function. Can you tell me what could be wrong? The answer for country Costa Rica and year 2019 is 60. (60 for attribute 1 and 2 for atrribute 2).
The other thing I am trying to do is a count distinct of codes and for attribute 1, were the column values can be dependant on a parameter scroller and have it as flexible as possible.
For example.
The dax should count me the unique column of codes for attribute 1 were the values are equal to 0 selected on the parameter.
In that case the answer would be 9.
Pretty much the column value should be equal to whatever the you pick up on the parameter scroller.
I attach the pbix.
https://1drv.ms/u/s!ApgeWwGTKtFdhkQ4g8ZDs2ScOAAU?e=v5fFce
Thanks!
Solved! Go to Solution.
Hi @o59393 ,
Please try like this:
Distinct count formulas_Parameters =
CALCULATE (
DISTINCTCOUNT ( Test111[Code] ),
FILTER ( Test111, Test111[Value] = 0 && Test111[Attribute] = "Attribute 1" )
)
The conditions need to be contained in the function of FILTER and use && to connect them.
Reference:
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @o59393 ,
Do you mean like this?
Count rows distinct_Attribute 1 =
COUNTROWS (
FILTER (
GROUPBY ( Test111, Test111[Code], Test111[Attribute] ),
Test111[Attribute] = "Attribute 1"
)
)
Distinct count formulas_Parameters =
CALCULATE (
DISTINCTCOUNT ( Test111[Code] ),
FILTER ( Test111, Test111[Value] = Parameter[Parameter Value] )
)
If I misunderstand, please share a table or a screenshot of the expected result.
Looks good!
Just one thing. On your second dax, the countdistict should only be for Test111[Attribute] = "Attribute 1.
Is this ok?
Distinct count formulas_Parameters =
CALCULATE (
DISTINCTCOUNT ( Test111[Code] ),
FILTER ( Test111, Test111[Value] = 0 ), Test111[Attribute] = "Attribute 1"
)
Thanks!
Hi @o59393 ,
Please try like this:
Distinct count formulas_Parameters =
CALCULATE (
DISTINCTCOUNT ( Test111[Code] ),
FILTER ( Test111, Test111[Value] = 0 && Test111[Attribute] = "Attribute 1" )
)
The conditions need to be contained in the function of FILTER and use && to connect them.
Reference:
Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
65 | |
63 | |
52 | |
37 | |
36 |
User | Count |
---|---|
82 | |
67 | |
61 | |
46 | |
45 |