cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
tlivingston
Frequent Visitor

Return Non-Blank Values From Multiple Columns With Delimiters

I have the following table:

 

ID

DogCatPigHorseCowSheep

1

Dog     
2 Cat   Sheep
3      
4  PigHorseCow 

 

I'm trying to create a calculated column that would populate a string based on the non-blank values of EACH of the six columns with a ", " delimiter. The results from above would be:

 

IDAnimals
1Dog
2Cat, Sheep
3None
4Pig, Horse, Cow

 

I've tried doing nested CONCATENATE and IF statements, but the string separation is the most difficult part. Essentially, I'm looking for something akin to TEXTJOIN from Excel. Anyone point me in the right direction?

 

This is a created table within my model, so I unfortuantely can't use any of the M table.join functions to help.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User IV
Super User IV

Re: Return Non-Blank Values From Multiple Columns With Delimiters

So like this?

 

TextJoin = 
  VAR __Table = { [Dog], [Cat], [Pig], [Horse], [Cow], [Sheep] }
RETURN
  CONCATENATEX(
      FILTER(__Table,[Value]<>""),
      [Value],
      ","
  )

 

PBIX attached.


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
Super User IV
Super User IV

Re: Return Non-Blank Values From Multiple Columns With Delimiters

So like this?

 

TextJoin = 
  VAR __Table = { [Dog], [Cat], [Pig], [Horse], [Cow], [Sheep] }
RETURN
  CONCATENATEX(
      FILTER(__Table,[Value]<>""),
      [Value],
      ","
  )

 

PBIX attached.


---------------------------------------

Not the Power BI thought police...

I have NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!
Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!

View solution in original post

tlivingston
Frequent Visitor

Re: Return Non-Blank Values From Multiple Columns With Delimiters

Thanks Greg! Worked like a charm.

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Top Solution Authors
Top Kudoed Authors