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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
sdsai777
Frequent Visitor

Comma separated column where/If condition

Hello All,

 

I have a unique ID and a CONCAT column with comma seperated value and Item ID. Below is the data set and the result expected.

 

IDCONCAT columnItem ID
1100, 200, 300, 400 , 500100, 300
2700, 800, 100, 200, 300100
31000, 2000, 3000, 4000500
81000100
61000, 2000, 200, 80008000
4100, 5001000, 100

IF the item ID has any one value in the CONCAT column then Y else N.

The above is just a sample data and the list of CONCAT columns is very big. I tried to split the column via comma it gave me like 100 extra columns in which I was not able to do a IF/where condition.

Below is the expected result

IDCONCAT columnItem IDIndicator
1100, 200, 300, 400 , 500100, 300Y
2700, 800, 100, 200, 300100Y
31000, 2000, 3000, 4000500N
81000100N
61000, 2000, 200, 80008000Y
4100, 5001000, 100Y

 

Thanks for looking at this and let me know if there is any solution.

6 REPLIES 6
v-jayw-msft
Community Support
Community Support

Hi @sdsai777 ,

 

Check this blog.

https://dax.tips/2019/07/05/dax-pivot-text-into-a-list-of-words/ 

List the values for both CONCAT column and Item ID then you may compare them.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
mahoneypat
Employee
Employee

Looking up a single ID in the Concat List is straight forward with SEARCH, but it is trickier to find the commas, parse out the characters before/after it, remove the spaces and then SEARCH for those is the Concat column.

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


FrankAT
Community Champion
Community Champion

Hi @sdsai777 ,

take a look at the following link:

 

http://sqljason.com/2013/06/split-delimited-row-into-multiple-rows.html

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

Thanks for the reply Frank, but I am looking at a where/IF condition without splitting the column.

 

Thanks

In the query editor, you can add a custom column and put this formula in the pop-up box.

 

let

concatlist = List.Transform(Text.Split([CONCAT column], ","), each Text.Trim(_)),
IDlist = List.Transform(Text.Split([Item ID], ","), each Text.Trim(_))
in
if List.Count(List.Intersect({concatlist, IDlist}))>0 then "Y" else "N"

 

The List.Transform function is needed as sometimes you have an extra space between list items.  This removes the spaces if there.

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks for the reply Pat. This table is derived using DAX statement in Power BI desktop and I am unable to edit it in Power Query. Is there any way to do using DAX statement?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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