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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
ABHIPRAYAM
Frequent Visitor

how to write a Dax for distinct count from above table to result table

Screenshot 2023-07-24 122326.png

1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

Hello @ABHIPRAYAM 

Please find the below DAX code for your ourput. Ideally, This should do this in Power Query or ETL level. But, here it is the dax code.

Output =
VAR _1 =
SUMMARIZE (
    'Table',
    [Name] )
   
VAR _2 =
ADDCOLUMNS(
_1,"Count",
1 + (Len ( [Name] ) ) - ( LEN( SUBSTITUTE( [Name],",","") ) )
)

VAR _3 =
CROSSJOIN(
_2,Table2 )

VAR _4 =
FILTER(
_3, [ID] <= [Count]
)

VAR _5 =
ADDCOLUMNS(
_4,"name2",
PATHITEM (
SUBSTITUTE ( [Name], ",", "|"),
      [ID]
      ) )
VAR _6 =
SELECTCOLUMNS(
    _5,"ExtractName",[name2]
)
VAR _Result =
DISTINCT(
    _6
)
RETURN
_Result
 
Please find the below screenshot as well
sanalytics_0-1690192520991.png

 

Hope this will help you.

 

Regards

sanalytics

If it is your solution then please like and accept it as solution

 

View solution in original post

4 REPLIES 4
ABHIPRAYAM
Frequent Visitor

Hi @sanalytics  can you plz share the screen shot of the dax which you have done  so it helps me better to understand.

Hey @ABHIPRAYAM 

I was solving this problem fromy my office laptop.So could not attach the solution to external link.

 

Here you go

https://www.transfernow.net/en/dltransfer?utm_source=20230725GwFtEX33

 

let me know if you need anything else. Would appreciate your like.

 

Regards

sanalytics

If it is your solution then please like and accept it as solution

@sanalytics  understood the approch but cant we calculate  without ID tables because if you have about 150 unique names and if we want to find Distinct count how can we do that

sanalytics
Super User
Super User

Hello @ABHIPRAYAM 

Please find the below DAX code for your ourput. Ideally, This should do this in Power Query or ETL level. But, here it is the dax code.

Output =
VAR _1 =
SUMMARIZE (
    'Table',
    [Name] )
   
VAR _2 =
ADDCOLUMNS(
_1,"Count",
1 + (Len ( [Name] ) ) - ( LEN( SUBSTITUTE( [Name],",","") ) )
)

VAR _3 =
CROSSJOIN(
_2,Table2 )

VAR _4 =
FILTER(
_3, [ID] <= [Count]
)

VAR _5 =
ADDCOLUMNS(
_4,"name2",
PATHITEM (
SUBSTITUTE ( [Name], ",", "|"),
      [ID]
      ) )
VAR _6 =
SELECTCOLUMNS(
    _5,"ExtractName",[name2]
)
VAR _Result =
DISTINCT(
    _6
)
RETURN
_Result
 
Please find the below screenshot as well
sanalytics_0-1690192520991.png

 

Hope this will help you.

 

Regards

sanalytics

If it is your solution then please like and accept it as solution

 

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors