Forum Discussion
Unpivot data before expand/append
- 1 year ago
Hi Anonymous ,
Thank you for reaching out to Microsoft Fabric Community.
Thank you RicoZhou Ilgar_Zarbali for the prompt response.
1. Handling 50+ Columns Without Hardcoding
You are right - hardcoding column names won’t scale. To handle any number of columns (even future ones), use:
let
Source = Excel.CurrentWorkbook(){[Name="YourTableName"]}[Content],
// Replace "YourTableName" with your actual table or range name
Unpivoted = Table.UnpivotOtherColumns(Source, {"Block"}, "Week", "Value")
in
UnpivotedThis automatically unpivots all columns except "Block", no matter how many there are or how often they change.
2. "Looping Through Each Block" Automatically
You don’t need a manual loop. Power Query is already row-wise by design.
Once unpivoted as shown above, your data will look like expected for example:
Block Week Value
A Week 1 123From here, you can:
1.Group by Block
2.Pivot Week if needed
3.Or analyze it as a clean, flat table
So there's no need to loop manually.Power Query handles that for every block and week combo automatically.
If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it!
Thank you.
Step #3: Dynamically Unpivot Columns with Week Label
Power Query Code Snippet (Step #3)
Here’s the code block for this step after your data is cleaned:
let
// Assume the cleaned data table is named #"Cleaned Table"
Source = #"Cleaned Table",
// Specify which columns to keep (others will be unpivoted)
ColumnsToKeep = {"Week", "Period"},
// Dynamically unpivot all other columns
UnpivotedData = Table.UnpivotOtherColumns(Source, ColumnsToKeep, "KPI Name", "KPI Value")
in
UnpivotedData
- Anonymous1 year agoNot applicable
Loop through each block, extract the corresponding week label > what is looping each block? how can I do that automatically?