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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Concatenate rows based on a shared ID using DAX

I have a table with data as below (representative only):

 

IDOrganismOrganism typeCountry
1001AplantUSA
1001AplantCanada
1001AplantMexico
1002BinsectGermany
1002BinsectFrance
1003CbacteriaChina
1004DvirusAustralia

 

and I want to display a table combining the countries rows so that there is only one entry for each ID, as so: 

IDOrganismorganism typeCountry
1001AplantUSA, Canada, Mexico
1002BinsectGermany, France
1003CbacteriaChina
1004DvirusAustralia

I need to do this using DAX and not in PowerQuery because there is a different part of the report where the countries do need to be separate. 

 

I am trying to write a measure but can't get it to work. I've tried using various combinations of concateneatex, combinevalues, calculate, filter, selectcolumns... but the closest I've gotten is for it to spit out a one row table listing all countries without regard to the ID, like this: 

IDOrganismOrganism typeCountry
Total  USA, Canada, Mexico, Germany, France, China, Australia


I tried to modify this solution https://community.fabric.microsoft.com/t5/Desktop/Concatenate-text-stored-in-several-rows/m-p/319615... like so: 
CALCULATE(CONCATENATEX('Table','Table'[Country]," "),FILTER('Table','Table'[ID]=EARLIER('TABLE'[ID]))

but the EARLIER formula is giving an error.


This feels like it should have a simple solution but I can't crack it, thanks!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , just create a measure like

 

CONCATENATEX('Table','Table'[Country]," ")

 

 

for the column you need

 

CONCATENATEX(FILTER('Table','Table'[ID]=EARLIER('TABLE'[ID]),'Table'[Country]," ")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , just create a measure like

 

CONCATENATEX('Table','Table'[Country]," ")

 

 

for the column you need

 

CONCATENATEX(FILTER('Table','Table'[ID]=EARLIER('TABLE'[ID]),'Table'[Country]," ")

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.