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
mmace1
Impactful Individual
Impactful Individual

How to manipulate this table? (Unpivot?)

If unpivot is even the correct term...

 

You can see, the vendorID is listed 6 times, one for each PaymentTypeID and its status (IsAllowed). 

Input.JPG

 

 

 

Can Power Query switch this so each VendorID is listed once, with 6 columns for each PaymentTypeID, and the values being the IsAllowed?  For example, mave Power Query transform things to look something like this. 

 

Output.JPG

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

See if this works, paste into Advanced Editor in a blank query

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWM3R59gV6VYHYiIMRCHBIUiBEwwlJhiiJihiBhhGGyEbrARqsGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [VendorID = _t, PaymentTypeID = _t, IsAllowed = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"VendorID", Int64.Type}, {"PaymentTypeID", Int64.Type}, {"IsAllowed", type logical}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"PaymentTypeID", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"PaymentTypeID", type text}}, "en-US")[PaymentTypeID]), "PaymentTypeID", "IsAllowed", List.Max)
in
    #"Pivoted Column"

If not, @ImkeF


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

See if this works, paste into Advanced Editor in a blank query

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSAWM3R59gV6VYHYiIMRCHBIUiBEwwlJhiiJihiBhhGGyEbrARqsGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [VendorID = _t, PaymentTypeID = _t, IsAllowed = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"VendorID", Int64.Type}, {"PaymentTypeID", Int64.Type}, {"IsAllowed", type logical}}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Changed Type", {{"PaymentTypeID", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Changed Type", {{"PaymentTypeID", type text}}, "en-US")[PaymentTypeID]), "PaymentTypeID", "IsAllowed", List.Max)
in
    #"Pivoted Column"

If not, @ImkeF


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
mmace1
Impactful Individual
Impactful Individual

That showed me enough to get it - thanks!  I don't want to post the code from the Advanced editor, but the setting I needed was this:  
Correct Pivot.JPG

 

 

Unfortunately it's extremely slow...but that may just be a limit of power query when the source table is almost 20m rows. 

Hmm, makes me think about something. A while ago I solved an slow Power Query unpivot issue using DAX.

 

https://community.powerbi.com/t5/Quick-Measures-Gallery/DAX-Unpivot/m-p/574832

 

Wonder if I could do something similar for a DAX Pivot... Hmm, I'll let you know if I figure that one out.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.