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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Power query assistance

Power query

I would like to flatten or unpivot the dates columns, but because these column header change in future my query will break is there a way to unpivot these columns without the query breaking in future when column headers change? The date columns are daily customer requirements 

Dataset

product    available stock   07.02.2023  08.02.2023

b365                20                     0                15

b379                 14                    5                 7

 

the main aim is to return the date when stock runs out

1 REPLY 1
serpiva64
Solution Sage
Solution Sage

Hi,

You can get this

serpiva64_0-1676633311438.png

I think i've found a really short way and it seems all dynamic

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSjI2M1XSUTIyABIgbGiqFKsDEja3BPFMgARI3lwpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [product = _t, available_stock = _t, #"07.02.2023" = _t, #"08.02.2023" = _t]),
#"Grouped Rows" = Table.Group(Source, {"product", "available_stock"}, {{"Count", each _, type table [product=nullable text, available_stock=nullable text, 07.02.2023=nullable text, 08.02.2023=nullable text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Transpose( Table.DemoteHeaders( Table.RemoveColumns([Count],{"product", "available_stock"})))),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
#"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"Column1", "Column2"}, {"Column1", "Column2"}),
#"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"Column1", "Date"}, {"Column2", "Value"}})
in
#"Renamed Columns"

 

 

You can take a look at the attached file

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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 Solution Authors