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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Challenge : how to generate a table spliting each row to new rows (in DAX !)

I have a Table1, which contains a list of categories (using | as separator)

CodeCategories
1A|B|C
2D|E

 

And I would like to generate a new table Table2 

CodeCategory
1A
1B
1C
2D
2E

 

I tried to use GENERATE / PATHITEM / GENERATESERIES functions, but it doesn't work : it seems that the PATH functions are always evaluated to BLANK when it is evaluated for each row of the Table1 inside the GENERATE function

 

 

New Table2 = GENERATE(
    Table1;
    var pathtext = Table1[Categories]
    var indexTable = GENERATESERIES(1;PATHLENGTH(pathtext))
    var categoryTable = GENERATE(indexTable;ROW("category";PATHITEM(pathtext;[Value];TEXT)))
    return categoryTable
)

 

 

Spoiler
 DAX errror : "The arguments in GenerateSeries function can not be blank"

Do you have any proposition to generate the table (with DAX) ?
Thanks,
Gregoire
Spoiler
 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Here's the table:

Expansion = 
SELECTCOLUMNS(
    ADDCOLUMNS(
        GENERATE(
            Data,
            var __path = Data[Categories]
            return
                SELECTCOLUMNS(
                    GENERATESERIES(1, PATHLENGTH( __path ) ),
                    "@CategoryPosition", [Value]
                )
        ),
        "@Category", PATHITEM( Data[Categories], [@CategoryPosition] )
    ),
    "Code", Data[Code],
    "Category", [@Category]
)

 

Best

D

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Here's the table:

Expansion = 
SELECTCOLUMNS(
    ADDCOLUMNS(
        GENERATE(
            Data,
            var __path = Data[Categories]
            return
                SELECTCOLUMNS(
                    GENERATESERIES(1, PATHLENGTH( __path ) ),
                    "@CategoryPosition", [Value]
                )
        ),
        "@Category", PATHITEM( Data[Categories], [@CategoryPosition] )
    ),
    "Code", Data[Code],
    "Category", [@Category]
)

 

Best

D

Greg_Deckler
Community Champion
Community Champion

I wrote a DAX UNPIVOT quick measure here: https://community.powerbi.com/t5/Quick-Measures-Gallery/DAX-Unpivot/m-p/574832#M256

 

Trick is going to be splitting out your data but figured it might help.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

I'll take a look for a DAX way to do this but it is super simple in Power Query:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs5PSVXSUXJOLElNzy/KTC1WitWJVjIECjnWONU4g3lGQJ5LjatSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"(blank).1", type text}}),
    #"Promoted Headers" = Table.PromoteHeaders(#"Changed Type", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Code", Int64.Type}, {"Categories", type text}}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Changed Type1", "Categories", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Categories.1", "Categories.2", "Categories.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Categories.1", type text}, {"Categories.2", type text}, {"Categories.3", type text}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type2", {"Code"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"})
in
    #"Removed Columns"


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,

thanks sincerely foryour 2d response in DAX which works perfectly !!! thank you.😀

 

But sorry to say that your 1st proposal with Query-M will not work when there is more than 3 categories in Table1[Categories].

With Query-M, a better solution can be realized in one step only, by splitting a column into rows  (and it is working with any growing number of categories in the data source, which is of course a requirement)

 

let
    Source = Table1,
    #"Split Column into rows" = Table.ExpandListColumn(Table.TransformColumns(Source, {{"Categories", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Categories")
in
    #"Split Column into rows"

 

 

Regards,

Gregoire

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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