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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
CarlosMarin11
New Member

help needed with unpivot columns

 Hi Everyone,

 

I´m seeking help and I´ll try to be as visual as possible while I explain with images:

 

Picture #1: This is the file I need to load directly to a model

PICTURE #1PICTURE #1

 

Picture #2: This is how I need it to be at the end of the steps of power Query

PICTURE 2PICTURE 2

 

Picture #3: This is the actual end of my steps in power query so far

IMAGE4.jpg

 

Picture #4: THE ISSUEEE 

IMAGE3.jpg

 

The rows between the green marks that I have made are the products that I need that beside these columns but I don´t know how to do it since the source file give me the information the way you can see in picture 1.

 

Please help

 

 

 

2 REPLIES 2
CarlosMarin11
New Member

Somethign like this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCg82MDBU0lFSitWJVgIxHMEsIyDLCcwyBrKcwSyQUiNkpS5wpa5wpW5wpcbISt3hSj3gSj2VYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Name", type text}}),
   
   
    trig = (n) => Text.StartsWith(n[Code], "WS"),
    keep = {"Code", "Name"},

     f = (t as table, trigger as function, keepCols as list) =>
        let 
            tbl = Table.Buffer(t), //Consider removal if the code runs slow//
            Pivot = List.Accumulate(Table.ToRecords(tbl), {}, (a, n)=> if  trig(n)
                                                                        then 
                                                                            {Record.SelectFields(n, keepCols) & [Nested = {[]}]} & a 
                                                                        else 
                                                                            {Record.SelectFields(List.First(a), keepCols) & [Nested = List.First(a)[Nested] & {n}]} & List.Skip(a)),
            Extract = Table.FromRecords(Pivot),
            Convert = Table.TransformColumns(Extract,{{"Nested", each Table.FromRecords(List.Skip(_))}})
        in Convert,
  

    out = f(#"Changed Type", trig, keep),
    #"Expanded Nested" = Table.ExpandTableColumn(out, "Nested", {"Code", "Name"}, {"Nested.Code", "Nested.Name"})
in #"Expanded Nested"

Copy f funciton to your query and then call it in the way demonstrated in the out step.Kind regards,

John

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors