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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
ngct1112
Post Patron
Post Patron

Measure - how to CONCATENATEX DITINCT value in a measure

Hi, I would like to ask is there any way I could concatenate all distinct value for a measure.

In this example, "Product" is a MEASURE.

I hope I can get a result "A, B, C", using sth like

=Calculate(Concatenatex(Table,Distinct(Table[Product]),", ")

Thanks for any idea!

IDProduct(measure)
1A
2A
3B
4C
5C
2 ACCEPTED SOLUTIONS
thedatahiker
Employee
Employee

Hi @ngct1112 
I would try this. 

Create a new table within a variable and add your measure as a column in that table. Here is documentation on ADDCOLUMN: ADDCOLUMNS function (DAX) - DAX | Microsoft Docs

 

Return that table variable in a concatenatex statement and return the new column you created.

 

MeasureName = 
VAR TableVar = 
ADDCOLUMN ( Table, "NewColumnName", [Measure] )
RETURN
CONCATENATEX ( TableVar, [NewColumnName], "," )

 

 

View solution in original post

v-yalanwu-msft
Community Support
Community Support

Hi, @ngct1112 ;

You could try:

MeasureName = 
VAR _new = 
DISTINCT(SELECTCOLUMNS( 'Table', "New", [Measure] ))
RETURN
CONCATENATEX ( _new, [New], "," )

he final output is shown below:

vyalanwumsft_0-1628233488404.png

Best Regards,
Community Support Team_ Yalan Wu
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

5 REPLIES 5
v-yalanwu-msft
Community Support
Community Support

Hi, @ngct1112 ;

You could try:

MeasureName = 
VAR _new = 
DISTINCT(SELECTCOLUMNS( 'Table', "New", [Measure] ))
RETURN
CONCATENATEX ( _new, [New], "," )

he final output is shown below:

vyalanwumsft_0-1628233488404.png

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-yalanwu-msft , your measure somehow works perfectly in my model. Great thanks for that!

thedatahiker
Employee
Employee

Hi @ngct1112 
I would try this. 

Create a new table within a variable and add your measure as a column in that table. Here is documentation on ADDCOLUMN: ADDCOLUMNS function (DAX) - DAX | Microsoft Docs

 

Return that table variable in a concatenatex statement and return the new column you created.

 

MeasureName = 
VAR TableVar = 
ADDCOLUMN ( Table, "NewColumnName", [Measure] )
RETURN
CONCATENATEX ( TableVar, [NewColumnName], "," )

 

 

@thedatahiker , With your provided solution, I am still getting "A,A,B,C,C". May I ask how I could only concate the distinct values?"A,B,C"

Great thanks again.

ngct1112_0-1628145966489.png

 

Hi @ngct1112 ,

 

To get distinct values you can update your code as below:-

MeasureName =
VAR TableVar =
    SELECTCOLUMNS ( 'Table_product', "NewColumnName", [Product(measure)] )
RETURN
    CONCATENATEX ( DISTINCT ( TableVar ), [NewColumnName], "," )

 

Samarth_18_0-1628148439818.png

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.