Forum Discussion
Comma Separated to One Row using DAX
Hi all - I have some data (see sample attached), which has been derived using the following DAX:
This DAX looks up examinations from a table called 'Activity' and finds which one it is, between two dates. Works really well. However, some of the lines are pulling back multiple exams (which is correct) but rather than having them on one line, separated by commas, I'd like them on a separate row, identifed and by using a field called 'Report ID' which is a unique code for each exam / exam combination.
Is there a way to either modify this DAX, to accomplish this. Or, is there a way to add another column and perform another DAX on this result, to produce the desired result?
I've linked to some sample data which hopefully shows you what I mean - the left set of data represents what I have, the right side shows what I'd like to have once the examinations are separated and put onto a separate row.
Many thanks!
Hi Creative_tree88 ,
You can achieve the desired result by creating a new calculated table using the following DAX:
NewTable = VAR Separator = "|" RETURN SELECTCOLUMNS( GENERATE( 'YourOriginalTable', VAR ExaminationsList = SUBSTITUTE('YourOriginalTable'[Examinations], ",", Separator) RETURN SELECTCOLUMNS( GENERATESERIES(1, LEN(ExaminationsList) - LEN(SUBSTITUTE(ExaminationsList, Separator, "")) + 1), "Report ID2", [Report ID], "SplitValue", PATHITEM(ExaminationsList, [Value], TEXT) ) ), "Report ID2", [Report ID2], "SplitValue", [SplitValue] )
Your output will look like this:Make sure to replace table and columns names with your owns.
3 Replies
- Kedar_PandeSuper User
- In Power query, select the column containing the comma-separated exams.
- Use the Split Column functionality to split the exams into separate rows. You can use the Split to Rows feature or perform a custom split by delimiter.
- Add the Report ID column by referencing the unique code for each exam in the table.
💌 If this helped, a Kudos 👍 or Solution mark ✅ would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn - Creative_tree88Helper V
Kedar_Pande Thanks. However, this needs to be done in DAX, not Power Query. The column is a calculated column based on DAX query, so does not appear on Power Query. Appreciate your reply though - would have been nice and simple if this was the case.
- Bibiano_GeraldoSuper User
Hi Creative_tree88 ,
You can achieve the desired result by creating a new calculated table using the following DAX:
NewTable = VAR Separator = "|" RETURN SELECTCOLUMNS( GENERATE( 'YourOriginalTable', VAR ExaminationsList = SUBSTITUTE('YourOriginalTable'[Examinations], ",", Separator) RETURN SELECTCOLUMNS( GENERATESERIES(1, LEN(ExaminationsList) - LEN(SUBSTITUTE(ExaminationsList, Separator, "")) + 1), "Report ID2", [Report ID], "SplitValue", PATHITEM(ExaminationsList, [Value], TEXT) ) ), "Report ID2", [Report ID2], "SplitValue", [SplitValue] )
Your output will look like this:Make sure to replace table and columns names with your owns.