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
aqeel_shaikh
Helper II
Helper II

Change in Table field

I have a case study, where i need to move the price and q'ty from vertical field to horizontal field.

 

First table is my actual data. PNR is the common field but i have multiple price and qty break up which i need in one field.below expected result provided.

PNRPriceQty Break
0046098-100 631.00 60.00
0046098-100 945.00 36.00
0046098-100 3405.00 0.00
0046098-100 1277.00 10.00

 

This is how i need the output.

PNRQTY Price (1)QTY Break (1)QTY Break (2)QTY Price (2)QTY Break (3)QTY Price (3)QTY Break (4)QTY Price (4)QTY Break (5)QTY Price (5)
0046098-100631.0060.003694503405101277151111
1 ACCEPTED SOLUTION
dufoq3
Super User
Super User

Hi @aqeel_shaikh, two more solutions:

 

Output

dufoq3_0-1726830062847.png

 

v1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lEyMzbUgzAMQHSsDroCSxNTiAJjM+wKjE0MoCpwmGBoZG4OUWAIURELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"),
    Grouped = Table.Group(ChangedType, {"PNR"}, {{"All", each 
        [ AddedIndex = Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type),
          UnpivotedOtherColumns = Table.UnpivotOtherColumns(AddedIndex, {"PNR", "Index"}, "Attribute", "Value"),
          MergedColumns = Table.CombineColumns(Table.TransformColumnTypes(UnpivotedOtherColumns, {{"Index", type text}}, "sk-SK"),{"Attribute", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Attribute"),
          PivotedColumn = Table.Pivot(MergedColumns, List.Distinct(MergedColumns[Attribute]), "Attribute", "Value")
        ][PivotedColumn], type table}}),
    Combined = Table.Combine(Grouped[All])
in
    Combined

 

v2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lEyMzbUgzAMQHSsDroCSxNTiAJjM+wKjE0MoCpwmGBoZG4OUWAIURELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"),
    GroupedRows = Table.Group(ChangedType, {"PNR"}, {{"All", each 
        List.Accumulate(
            {0..Table.RowCount(_)-1},
            Table.FirstN(Table.RemoveColumns(_, {"Price", "Qty Break"}), 1),
            (s,c)=> Table.AddColumn(Table.AddColumn(s, "Price " & Text.From(c+1), (x)=> [Price]{c}, Currency.Type), "Qty Break " & Text.From(c+1), (y)=> [Qty Break]{c}, type number)), type table}}),
    Combined = Table.Combine(GroupedRows[All])
in
    Combined

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

10 REPLIES 10
dufoq3
Super User
Super User

Hi @aqeel_shaikh, two more solutions:

 

Output

dufoq3_0-1726830062847.png

 

v1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lEyMzbUgzAMQHSsDroCSxNTiAJjM+wKjE0MoCpwmGBoZG4OUWAIURELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"),
    Grouped = Table.Group(ChangedType, {"PNR"}, {{"All", each 
        [ AddedIndex = Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type),
          UnpivotedOtherColumns = Table.UnpivotOtherColumns(AddedIndex, {"PNR", "Index"}, "Attribute", "Value"),
          MergedColumns = Table.CombineColumns(Table.TransformColumnTypes(UnpivotedOtherColumns, {{"Index", type text}}, "sk-SK"),{"Attribute", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Attribute"),
          PivotedColumn = Table.Pivot(MergedColumns, List.Distinct(MergedColumns[Attribute]), "Attribute", "Value")
        ][PivotedColumn], type table}}),
    Combined = Table.Combine(Grouped[All])
in
    Combined

 

v2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lEyMzbUgzAMQHSsDroCSxNTiAJjM+wKjE0MoCpwmGBoZG4OUWAIURELAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"),
    GroupedRows = Table.Group(ChangedType, {"PNR"}, {{"All", each 
        List.Accumulate(
            {0..Table.RowCount(_)-1},
            Table.FirstN(Table.RemoveColumns(_, {"Price", "Qty Break"}), 1),
            (s,c)=> Table.AddColumn(Table.AddColumn(s, "Price " & Text.From(c+1), (x)=> [Price]{c}, Currency.Type), "Qty Break " & Text.From(c+1), (y)=> [Qty Break]{c}, type number)), type table}}),
    Combined = Table.Combine(GroupedRows[All])
in
    Combined

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

let
    Source = Excel.Workbook(File.Contents("C:\Users\s441801\Desktop\Pricelist 2023 CHF_cal-day_updated.xlsx"), null, true),
    Prices_Sheet = Source{[Item="Prices",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Prices_Sheet, [PromoteAllScalars=true]),
    #"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"Column4"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Price", Currency.Type}, {"Qty Break", Int64.Type}}),
    #"Grouped Rows" = Table.Group(ChangedType, {"PNR"}, {{"All", each [ AddedIndex = Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type),
    #"UnpivotedOtherColumns" = Table.UnpivotOtherColumns(AddedIndex, {"PNR", "Index"}, "Attribute", "Value"),
    #"MergedColumns" = Table.CombineColumns(Table.TransformColumnTypes(UnpivotedOtherColumns, {{"Index", type text}}, "sk-SK"),{"Attribute", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Attribute"),
    #"PivotedColumn" = Table.Pivot(MergedColumns, List.Distinct(MergedColumns[Attribute]), "Attribute", "Value")][PivotedColumn], type table}}),
    #"Combined" = Table.Combine(Groupe Rows[All])
in
    #"Combined"

@dufoq3 , i tried V1 can you please check as i getting below error

aqeel_shaikh_0-1727074766814.png

 

 

 

You're missing comma somewhere. Which step caused an error?

Try this, but I've just combined your beginning of the query with mine.

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\s441801\Desktop\Pricelist 2023 CHF_cal-day_updated.xlsx"), null, true),
    Prices_Sheet = Source{[Item="Prices",Kind="Sheet"]}[Data],
    PromotedHeaders = Table.PromoteHeaders(Prices_Sheet, [PromoteAllScalars=true]),
    RemovedColumns = Table.RemoveColumns(Promoted Headers,{"Column4"}),
    ChangedType = Table.TransformColumnTypes(RemovedColumns,{{"Price", Currency.Type}, {"Qty Break", type number}}, "en-US"),
    Grouped = Table.Group(ChangedType, {"PNR"}, {{"All", each 
        [ AddedIndex = Table.AddIndexColumn(_, "Index", 1, 1, Int64.Type),
          UnpivotedOtherColumns = Table.UnpivotOtherColumns(AddedIndex, {"PNR", "Index"}, "Attribute", "Value"),
          MergedColumns = Table.CombineColumns(Table.TransformColumnTypes(UnpivotedOtherColumns, {{"Index", type text}}, "sk-SK"),{"Attribute", "Index"}, Combiner.CombineTextByDelimiter(" ", QuoteStyle.None), "Attribute"),
          PivotedColumn = Table.Pivot(MergedColumns, List.Distinct(MergedColumns[Attribute]), "Attribute", "Value")
        ][PivotedColumn], type table}}),
    Combined = Table.Combine(Grouped[All])
in
    Combined

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

@dufoq3- Hi, Thanks for the revert, showing error for below aqeel_shaikh_0-1727174837262.png

#"Promoted Headers" = Table.PromoteHeaders(Prices_Sheet, [PromoteAllScalars=true]),

 

@dufoq3 - V1 worked...Thanks

 

You're welcome. Enjoy 😉


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

Omid_Motamedise
Super User
Super User

This is step by step solution

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAwMTOwtNA1NDBQ0lFSMDM21IOyDECMWB0MJZYmplAlxmY4lBibGMDU4DLF0MjcHKrEEKImFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [PNR = _t, Price = _t, #"Qty Break" = _t]),
Custom1 = Table.Group(Source, "PNR", {"S1", each _}),
#"Added Custom" = Table.AddColumn(Custom1, "Custom", each Table.RemoveColumns([S1],"PNR")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Table.ToRows([Custom])),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each List.Combine([Custom.1])),
Custom2 = Table.SplitColumn(#"Added Custom2", "Custom.2", each _)
in
Custom2

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
AlienSx
Super User
Super User

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], 
    group = Table.Group(Source, "PNR", {"x", (x) => List.Combine(List.Zip({x[Price], x[Qty Break]}))}),
    split = Table.SplitColumn(group, "x", (x) => x)
in
    split

@AlienSx what does "x" stands in the table here ?

column name

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.