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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Barkop_1
Frequent Visitor

Distinctcount based on conditions in multiple columns

Hello, I need dax measure that calculates distinct count of ID column , based on condition form three different columns A,B and C.

Dictinctcount should be calculated when at least of column (A, B, C) has value = 1.

Additionally user can deselect for example column B from calculation, so that then dax should be calculted only on column A, C.

 

Intuitively i would assume it should be something like below, but I am still trying to figure out row/column contex and general DAX rules: 

DistCount = calculate(distinctcount(RawData[ID]) , AND([IsA],RawData[A]=1) || AND([IsB],RawData[B]=1) || AND([IsC],RawData[C]=1) )
 
Przechwytywanie.JPG
1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @Barkop_1 

According to your description, you want to "calculates distinct count of ID column , based on condition form three different columns A,B and C.".

Here are the steps you can refer to :
(1)We need to unpivot your table in Power Query Editor :
We need to select the three columns "A,B,C" and click "Unpivot columns":

vyueyunzhmsft_0-1692241008554.png

Then we can change the column name like this:

vyueyunzhmsft_1-1692241043604.png

 

Then we can apply the data to desktop .

 

(2)Then we can create a measure like this:

Measure = CALCULATE( DISTINCTCOUNT('Table'[ID]) , 'Table'[Value] =1)

Then we can get your end result as follows:

vyueyunzhmsft_2-1692241105887.png

 

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

Hi , @Barkop_1 

According to your description, you want to "calculates distinct count of ID column , based on condition form three different columns A,B and C.".

Here are the steps you can refer to :
(1)We need to unpivot your table in Power Query Editor :
We need to select the three columns "A,B,C" and click "Unpivot columns":

vyueyunzhmsft_0-1692241008554.png

Then we can change the column name like this:

vyueyunzhmsft_1-1692241043604.png

 

Then we can apply the data to desktop .

 

(2)Then we can create a measure like this:

Measure = CALCULATE( DISTINCTCOUNT('Table'[ID]) , 'Table'[Value] =1)

Then we can get your end result as follows:

vyueyunzhmsft_2-1692241105887.png

 

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

amitchandak
Super User
Super User

@Barkop_1 , a better idea would to unpivot the column and then use a distinct count on it

Unpivot Data(Power Query): https://youtu.be/2HjkBtxSM0g

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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