cancel
Showing results for
Did you mean: Helper I

## DAX To Split into Rows on Delimeter

Hello All. So I have an Employee data set.  I needed to get the hierarchal structure of the company so I used the PATH function to achieve this.  but now I have an additional requirement that requires me to parse this column and I can't figure out how to do this.

The result of the PATH function looks like this

0175|0116|0423|0066|0001

I need to split this column into ROWS based on delimter.  There must be a DAX function to achieve this.

Thanks

1 ACCEPTED SOLUTION Anonymous
Not applicable

1) Create a linked table for the Student.

2) Create a table called DummyTbl which is just a list of running numbers from 1 till n. The value of n should be equal to the max number of subjects that a student can have. In this demo, I am assuming that a student can have a max of 10 subjects, so my Dummy table will consist of numbers 1 – 10.

3) Now let us create the DAX queries in DAX Studio. First, we will create a computed column called SubCnt which will give the number of subjects for each row.

EVALUATE
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
)

4) The only way we can increase the number of rows of a table is by using the function CrossJoin. So let us CrossJoin the Student table with the DummyTbl.

EVALUATE
Crossjoin (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
)

5) Now filter the resultant table where SubCnt is less than or equal to Dummy column. Now we have got the exact number of rows needed for the end result.

EVALUATE
Filter (
Crossjoin (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
),
DummyTbl[Dummy] <= [SubCnt]
)

6) The only thing left is to split the delimited subjects to the single subject for each row. And the only way to split delimited values is to use the PATHITEM function. To use the PATHITEM function, we should substitute the commas (,) with the pipe (|) symbol.

EVALUATE
FILTER (
CROSSJOIN (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
),
DummyTbl[Dummy] <= [SubCnt]
),
“SubName”,
PATHITEM (
SUBSTITUTE ( Student[Subject], “,”, “|” ),
DummyTbl[Dummy]
)
)

7) Now all we need to do is to select the two required columns.

EVALUATE
SUMMARIZE (
FILTER (
CROSSJOIN (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
),
DummyTbl[Dummy] <= [SubCnt]
),
“SubName”,
pathitem (
Substitute ( Student[Subject], “,”, “|” ),
DummyTbl[Dummy]
)
),
[StudentName],
[SubName]
)
ORDER BY [StudentName]

11 REPLIES 11 Anonymous
Not applicable

1) Create a linked table for the Student.

2) Create a table called DummyTbl which is just a list of running numbers from 1 till n. The value of n should be equal to the max number of subjects that a student can have. In this demo, I am assuming that a student can have a max of 10 subjects, so my Dummy table will consist of numbers 1 – 10.

3) Now let us create the DAX queries in DAX Studio. First, we will create a computed column called SubCnt which will give the number of subjects for each row.

EVALUATE
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
)

4) The only way we can increase the number of rows of a table is by using the function CrossJoin. So let us CrossJoin the Student table with the DummyTbl.

EVALUATE
Crossjoin (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
)

5) Now filter the resultant table where SubCnt is less than or equal to Dummy column. Now we have got the exact number of rows needed for the end result.

EVALUATE
Filter (
Crossjoin (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
),
DummyTbl[Dummy] <= [SubCnt]
)

6) The only thing left is to split the delimited subjects to the single subject for each row. And the only way to split delimited values is to use the PATHITEM function. To use the PATHITEM function, we should substitute the commas (,) with the pipe (|) symbol.

EVALUATE
FILTER (
CROSSJOIN (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
),
DummyTbl[Dummy] <= [SubCnt]
),
“SubName”,
PATHITEM (
SUBSTITUTE ( Student[Subject], “,”, “|” ),
DummyTbl[Dummy]
)
)

7) Now all we need to do is to select the two required columns.

EVALUATE
SUMMARIZE (
FILTER (
CROSSJOIN (
SUMMARIZE (
Student,
[StudentName],
[Subject],
“SubCnt”,
1 + Len ( [Subject] ) – Len ( Substitute ( [Subject], “,”, “” ) )
),
DummyTbl
),
DummyTbl[Dummy] <= [SubCnt]
),
“SubName”,
pathitem (
Substitute ( Student[Subject], “,”, “|” ),
DummyTbl[Dummy]
)
),
[StudentName],
[SubName]
)
ORDER BY [StudentName] @Anonymous  Sir you are the new DAX God! 🙂 This worked like a charm for my case. I had created a comma separated "Data discrepency Alerts" using Calculated column and the Alerts then needed to be split them into Rows! Your solution is all I had to look at. THANK YOU SO MUCH! This should be documented, blogged! Microsoft

Did you get solution Please share if you can? Helper I Super User

Are you trying to obtain end results similar to https://www.daxpatterns.com/parent-child-hierarchies/#organizational-structure?

I do not believe the intention of PATH is phyically alter the table but rather allow you to access levels within the path with PATHITEM( ).

Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User! Helper I

Sort of...i already achieved those particular results.  I am trying to get to the next level. Each employee is on multiple "Teams" as denoted by the Path. I need to be able to list those teams out in rows by employee. Super User

Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User! Helper I

I can't provide a sample. Apologies. Against company policy.  though all i need to know is if there is a way to split the values in a column into rows based on delimiter. Using DAX. The values are separated by a pipe. Resolver III

This sounds like something you want to do within the Query Editor. You can split a column by delimiter (Transform ribbon > Split Column > by Delimiter)

In the window that pops up, you can change the delimiter to Custom (and enter " | " ), and in the Advanced Options, choose "Split into Rows" as shown in the attached image. Helper III

I have successfully used a DAX expression from Chris Webb - its a bit "complicated" but performance is quite good:
A New Approach To Handling SSRS Multi-Valued Parameters in DAX Queries

``````EVALUATE
VAR OrderList = "SO43713|SO43758|SO43784|SO43821"
VAR OrderCount =
PATHLENGTH ( OrderList )
VAR NumberTable =
GENERATESERIES ( 1, OrderCount, 1 )
VAR OrderTable =
GENERATE (
NumberTable,
VAR CurrentKey = [Value]
RETURN
ROW ( "Key", PATHITEM ( OrderList, CurrentKey ) )
)
VAR GetKeyColumn =
SELECTCOLUMNS ( OrderTable, "Key", [Key] )
VAR FilterTable =
TREATAS ( GetKeyColumn, FactInternetSales[SalesOrderNumber] )
RETURN
CALCULATETABLE ( FactInternetSales, FilterTable )`````` Helper I

I cannot use Power Query as the column I need to parse is a calculated column. Announcements #### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023. #### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers! #### 2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture. Top Solution Authors
Top Kudoed Authors
Users online (4,263)
{"ft_lang_label":"__label__en","ft_lang_prob":0.80211645,"math_prob":0.6768766,"size":7651,"snap":"2022-40-2023-06","text_gpt3_token_len":2084,"char_repetition_ratio":0.15012424,"word_repetition_ratio":0.6044118,"special_character_ratio":0.2868906,"punctuation_ratio":0.15054545,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9736036,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60],"im_url_duplicate_count":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,3,null,2,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-01-27T20:30:05Z\",\"WARC-Record-ID\":\"<urn:uuid:d52aaf6f-a987-468d-a796-a171792d3d1d>\",\"Content-Length\":\"677156\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:2e670f5d-a966-4705-85cc-28bb45d71cde>\",\"WARC-Concurrent-To\":\"<urn:uuid:333acf0e-76e4-447d-ae6b-55c678899f78>\",\"WARC-IP-Address\":\"104.72.120.81\",\"WARC-Target-URI\":\"https://community.powerbi.com/t5/Desktop/DAX-To-Split-into-Rows-on-Delimeter/m-p/1449757\",\"WARC-Payload-Digest\":\"sha1:S2NQRZYY6PUXRZQAZ67ND3LQTG7IOKXZ\",\"WARC-Block-Digest\":\"sha1:FAC3EQU3PJL2W7S7UBSSWMZLOSHACBMK\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764495012.84_warc_CC-MAIN-20230127195946-20230127225946-00686.warc.gz\"}"}