- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Add Rows - Loop
Hello everyone! 😊
Hope you're doing well!
Initial Situation
I'm currently working on tricky DB, please see below an example, wtih some informations stored in columns (ID/Date/Underlying) and some others vertically (Label/Level) (it's a bit hard to express clearly).
ID | Label | Level | Date | Underlying |
1 | Accumulation | 300 | 01/01/2024 | Potato |
1 | Barrier | 400 | 01/01/2024 | Potato |
2 | Up | 300 | 03/01/2024 | Green Beans |
2 | Down | 400 | 03/01/2024 | Green Beans |
2 | Middle | 450 | 03/01/2024 | Green Beans |
3 | Up | 300 | 05/01/2024 | Carrots |
3 | Down | 400 | 05/01/2024 | Carrots |
3 | Middle | 350 | 05/01/2024 | Carrots |
3 | Barrier | 500 | 05/01/2024 | Carrots |
Expected Result
I would like to display a table or matrix in PowerBI (based on a ID filter) as folow:
Example 1
ID | Accumulation | Barrier | Date | Underlying |
1 | 300 | 400 | 01/01/2024 | Potato |
Example 2
ID | Up | Down | Middle | Date | Underlying |
2 | 300 | 400 | 450 | 03/01/2024 | Green Beans |
Example 3
ID | Up | Down | Middle | Barrier | Date | Underlying |
3 | 300 | 400 | 350 | 14/05/1901 | 05/01/2024 | Carrots |
However...
So far, I'm a bit stuck as I cannot reach this result either with a Table or with a Matrix. Please see below an example:
*******************************************
In order to reach my result, I was thinking about creating a Looping Querry adding for each ID two additional rows as follow :
ID | Label | Level | Date | Underlying |
1 | Accumulation | 300 | 01/01/2024 | Potato |
1 | Barrier | 400 | 01/01/2024 | Potato |
1 | Date | 01/01/2024 | ||
1 | Underlying | Potato | ||
2 | Up | 300 | 03/01/2024 | Green Beans |
2 | Down | 400 | 03/01/2024 | Green Beans |
2 | Middle | 450 | 03/01/2024 | Green Beans |
2 | Date | 03/01/2024 | ||
2 | Underlying | Green Beans | ||
3 | Up | 300 | 05/01/2024 | Carrots |
3 | Down | 400 | 05/01/2024 | Carrots |
3 | Middle | 450 | 05/01/2024 | Carrots |
3 | Barrier | 500 | 05/01/2024 | Carrots |
3 | Date | 05/01/2024 | ||
3 | Underlying | Carrots |
I don't know if it's managable on PowerQuerry or if there is a easier way to reach the expected result in PowerBI. Any help would be greatly appreaciated! 🙏
Please find here the PBIX and Excel used for the example.
Many thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @GabinAM, Power Query solution:
Result (you can delete last step if you want to see separate tables)
let
Source = Excel.Workbook(File.Contents("Z:\support\Execution\GAM\Control - Check - Data\20240408 - ADM New DB\Test 2\TEST.xlsx"), true, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
ChangedType = Table.TransformColumnTypes(Sheet1_Sheet,{{"ID", Int64.Type}, {"Label", type text}, {"Level", Int64.Type}, {"Date", type date}, {"Underlying", type text}}),
GroupedRows = Table.Group(ChangedType, {"ID"}, {{"All", each Table.Pivot(_, List.Distinct([Label]), "Label", "Level"), type table}}),
CombinedAll = Table.Combine(GroupedRows[All])
in
CombinedAll
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @GabinAM, Power Query solution:
Result (you can delete last step if you want to see separate tables)
let
Source = Excel.Workbook(File.Contents("Z:\support\Execution\GAM\Control - Check - Data\20240408 - ADM New DB\Test 2\TEST.xlsx"), true, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
ChangedType = Table.TransformColumnTypes(Sheet1_Sheet,{{"ID", Int64.Type}, {"Label", type text}, {"Level", Int64.Type}, {"Date", type date}, {"Underlying", type text}}),
GroupedRows = Table.Group(ChangedType, {"ID"}, {{"All", each Table.Pivot(_, List.Distinct([Label]), "Label", "Level"), type table}}),
CombinedAll = Table.Combine(GroupedRows[All])
in
CombinedAll
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hello @dufoq3 it works wonderfully!
I'm just checking how can we hide the column if the value is null for the relevant ID?
Basicly, I have ~ 15/20 different ID with differents labels so it's not very handy to keep all of them on the table...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Hi @dufoq3 just to follow on this topic, you can display only the columns for the selected iteams by selecting the columns in PowerQuerry and then Unpivot Only Selected Columns.
let
Source = Excel.Workbook(File.Contents("Z:\support\Execution\GAM\Control - Check - Data\20240408 - ADM New DB\Test 2\TEST.xlsx"), true, true),
Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
ChangedType = Table.TransformColumnTypes(Sheet1_Sheet,{{"ID", Int64.Type}, {"Label", type text}, {"Level", Int64.Type}, {"Date", type date}, {"Underlying", type text}}),
GroupedRows = Table.Group(ChangedType, {"ID"}, {{"All", each Table.Pivot(_, List.Distinct([Label]), "Label", "Level"), type table}}),
CombinedAll = Table.Combine(GroupedRows[All]),
#"Unpivoted Only Selected Columns" = Table.Unpivot(CombinedAll, {"Accumulation", "Barrier", "Up", "Down", "Middle", "Higher", "Lower", "Haut", "Bas"}, "Attribute", "Value")
in
#"Unpivoted Only Selected Columns"
Then in a Matrix.
I guess you know this functionnality but just in case someone need it in the future!
Again many thanks for your help! 🙌
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
11-26-2024 09:14 PM | |||
12-18-2024 01:20 AM | |||
02-05-2024 07:06 PM | |||
03-07-2024 02:17 PM | |||
12-12-2023 12:59 PM |
User | Count |
---|---|
32 | |
32 | |
20 | |
15 | |
13 |
User | Count |
---|---|
19 | |
18 | |
16 | |
10 | |
9 |