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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
vinothkumar1990
Helper II
Helper II

Calculate the distinct Count

Hi,

I have a table which contains SID, State and State Code. I want to create a column which shows the distinct count of state code for each state.

Example,

Data
SIDStateState Code
1KarnatakaKA
2TamilnaduTN
3KeralaKL
4KarnatakaKA
5TamilnaduTNN
6DelhiDL
7TamilnaduTNU
8KeralaKRL

 

Expected Report
SIDStateState CodeDistictct CountComment
1KarnatakaKA11 - KA
2TamilnaduTN33 - TN, TNN and TNU
3KeralaKL22 -KL and KRL
4KarnatakaKA1Only KA
5TamilnaduTNN33 - TN, TNN and TNU
6DelhiDL11 - DL
7TamilnaduTNU33 - TN, TNN and TNU
8KeralaKRL22 -KL and KRL

 

Thanks in advance!

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @vinothkumar1990 

According to your description, you want to get the distincount of the [State Code] prt [State] .

 [1]If you want to create a calcuated column,  you can use this dax code:

Column = CALCULATE( DISTINCTCOUNT('Table'[State Code])  ,ALLEXCEPT('Table','Table'[State])  )
Column 2 = var _t  = CALCULATETABLE( DISTINCT('Table'[State Code]) , ALLEXCEPT('Table','Table'[State]))

return
CONCATENATEX(_t , [State Code] , ",")

 

The result is as follows:

vyueyunzhmsft_0-1690162464156.png

[2]If you want to create a measre , you can use this dax code and just put the field on the visual:

Measure = var _t = DISTINCT('Table'[State Code])
return
CONCATENATEX( _t , [State Code],",")

vyueyunzhmsft_1-1690162510145.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 , @vinothkumar1990 

According to your description, you want to get the distincount of the [State Code] prt [State] .

 [1]If you want to create a calcuated column,  you can use this dax code:

Column = CALCULATE( DISTINCTCOUNT('Table'[State Code])  ,ALLEXCEPT('Table','Table'[State])  )
Column 2 = var _t  = CALCULATETABLE( DISTINCT('Table'[State Code]) , ALLEXCEPT('Table','Table'[State]))

return
CONCATENATEX(_t , [State Code] , ",")

 

The result is as follows:

vyueyunzhmsft_0-1690162464156.png

[2]If you want to create a measre , you can use this dax code and just put the field on the visual:

Measure = var _t = DISTINCT('Table'[State Code])
return
CONCATENATEX( _t , [State Code],",")

vyueyunzhmsft_1-1690162510145.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

foodd
Super User
Super User

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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