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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
paulohk
New Member

Power Query transformation

Hello, 

the following data's are extract from a software and is presented as follow :

Column 1Column 2Column 3Column 4 Lot numberPiece
TEST NAMETEST ATEST BTEST CA000051
SITE01         460.2A000051
SITE02         460.3A000051
TEST NAMETEST ATEST BTEST CA000052
SITE01         250.3A000052
SITE02         260.3A000052

 

With power query, I would like to transport the table to get this, and have the test name in a column  : 

SITETEST NAMEVALUELot numberPiece
SITE01         TEST A4A000051
SITE01         TEST B6A000051
SITE01         TEST C0.2A000051
SITE02         TEST A4A000051
SITE02         TEST B6A000051
SITE02         TEST C0.3A000051
SITE01         TEST A2A000052
SITE01         TEST B5A000052
SITE01         TEST C0.3A000052
SITE02         TEST A2A000052
SITE02         TEST B6A000052
SITE02         TEST C0.3A000052

I supposed it could be usefull to use unpivot function, but i didn't managed to get the good result. Do you have an idea ?

Thanks for your help !

Have a good day.
 

1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @paulohk, check this:

 

Result

dufoq3_0-1721399790902.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnENDlHwc/R1VdKBsB1hDCcYwxnIcDQAAlMgw1ApVidaKdgzxNXAUAEGgOImQGwGxAZ6RjiUG2FXboypnFQ3GeFwE8glppiWGOFwkxF2NwGVxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column 1" = _t, #"Column 2" = _t, #"Column 3" = _t, #"Column 4" = _t, #" Lot number" = _t, Piece = _t]),
    PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(PromotedHeaders, {"TEST NAME", "A00005", "1"}, "Attribute", "Value"),
    RenamedColumns = Table.RenameColumns(UnpivotedOtherColumns,{{"TEST NAME", "SITE"}, {"Attribute", "TEST NAME"}, {"A00005", "Lot number"}, {"Value", "VALUE"}, {"1", "Piece"}}),
    FilteredRows = Table.SelectRows(RenamedColumns, each ([SITE] <> "TEST NAME")),
    ReorderedColumns = Table.ReorderColumns(FilteredRows,{"SITE", "TEST NAME", "VALUE", "Lot number", "Piece"})
in
    ReorderedColumns

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @paulohk, check this:

 

Result

dufoq3_0-1721399790902.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnENDlHwc/R1VdKBsB1hDCcYwxnIcDQAAlMgw1ApVidaKdgzxNXAUAEGgOImQGwGxAZ6RjiUG2FXboypnFQ3GeFwE8glppiWGOFwkxF2NwGVxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column 1" = _t, #"Column 2" = _t, #"Column 3" = _t, #"Column 4" = _t, #" Lot number" = _t, Piece = _t]),
    PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    UnpivotedOtherColumns = Table.UnpivotOtherColumns(PromotedHeaders, {"TEST NAME", "A00005", "1"}, "Attribute", "Value"),
    RenamedColumns = Table.RenameColumns(UnpivotedOtherColumns,{{"TEST NAME", "SITE"}, {"Attribute", "TEST NAME"}, {"A00005", "Lot number"}, {"Value", "VALUE"}, {"1", "Piece"}}),
    FilteredRows = Table.SelectRows(RenamedColumns, each ([SITE] <> "TEST NAME")),
    ReorderedColumns = Table.ReorderColumns(FilteredRows,{"SITE", "TEST NAME", "VALUE", "Lot number", "Piece"})
in
    ReorderedColumns

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hoki_34789
New Member

Saya sebagai siswa akuntansi ingin sekali belajar power bi, minta saranya?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.