Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
o59393
Post Prodigy
Post Prodigy

Countdistinct of multiple columns and what if parameter

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!

1 ACCEPTED 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:

DAX operators 

 

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.

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.

View solution in original post

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

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] )
)

7.PNG

If I misunderstand, please share a table or a screenshot of the expected result.

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 @v-xuding-msft 

 

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:

DAX operators 

 

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.

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.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.