Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
I have query data "Weekly Sales" that looks a bit like this (changed for confidentiality):
| Code | Desc | Qty | Index |
| Debtor: XYZ Debtor | 1 | ||
| 1010 | Product 1 | 12 | 2 |
| 1020 | Product 2 | 3 | 3 |
| 1030 | Product 3 | 4 | 4 |
| Debtor: PRT Debtor | 5 | ||
| 1010 | Product 1 | 44 | 6 |
| 1020 | Product 2 | 66 | 7 |
| 1030 | Product 3 | 3 | 8 |
Using this DAX:
Location = VAR a = 'Weekly Sales'[Index]
RETURN
CALCULATE (MAX ( 'Weekly Sales'[Desc] ),FILTER (ALL ( 'Weekly Sales' ),'Weekly Sales'[Index]= CALCULATE (MAX ( 'Weekly Sales'[Index] ),FILTER ( ALL ( 'Weekly Sales' ), 'Weekly Sales'[Index] <= a && LEFT('Weekly Sales'[Desc],6) = "Debtor" ))))
I get a calculated column that looks like this:
| Location | Code | Desc | Qty | Index |
| Debtor: XYZ Debtor | Debtor: XYZ Debtor | 1 | ||
| Debtor: XYZ Debtor | 1010 | Product 1 | 12 | 2 |
| Debtor: XYZ Debtor | 1020 | Product 2 | 3 | 3 |
| Debtor: XYZ Debtor | 1030 | Product 3 | 4 | 4 |
| Debtor: PRT Debtor | Debtor: PRT Debtor | 5 | ||
| Debtor: PRT Debtor | 1010 | Product 1 | 44 | 6 |
| Debtor: PRT Debtor | 1020 | Product 2 | 66 | 7 |
| Debtor: PRT Debtor | 1030 | Product 3 | 3 | 8 |
This is exactly what I need but I need it in the query not on the destop so that I can use it in a query join. Any help on how I can do this in query M or in the query editor would be very appreciated!
Solved! Go to Solution.
@BarbaraK in query editor start a blank query and paste the following code and you will see the step on how to create one
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJRcklNKskvslKIiIxSgLCBgkBkqBSrE61kaGBoAOQEFOWnlCaXKBiCJIyAhBFU1ghZFiRhDMYQSWNkSZCECRiDJJEsDggKQbHYFJfFJiDtZrgsNjMDEua4bAZhC6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t, Desc = _t, Qty = _t, Index = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Desc", type text}, {"Qty", Int64.Type}, {"Index", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Location", each if [Code] = null then [Desc] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Location"})
in
#"Filled Down"
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@BarbaraK in query editor start a blank query and paste the following code and you will see the step on how to create one
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WUtJRcklNKskvslKIiIxSgLCBgkBkqBSrE61kaGBoAOQEFOWnlCaXKBiCJIyAhBFU1ghZFiRhDMYQSWNkSZCECRiDJJEsDggKQbHYFJfFJiDtZrgsNjMDEua4bAZhC6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Code = _t, Desc = _t, Qty = _t, Index = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", Int64.Type}, {"Desc", type text}, {"Qty", Int64.Type}, {"Index", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Location", each if [Code] = null then [Desc] else null),
#"Filled Down" = Table.FillDown(#"Added Custom",{"Location"})
in
#"Filled Down"
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Oh that is beautiful. I'm pretty sure I've got it from here. 🙂
@BarbaraK that's awesome, glad to hear. Cheers!!
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
At the risk of sounding daft: This is my screen ATM and I am not really sure where to from here?
@BarbaraK right click on query1, and in pop up menu there is an option advanced editor , choose that and that is where you paste the code, make sure remove existing code
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 60 | |
| 49 | |
| 30 | |
| 25 | |
| 23 |
| User | Count |
|---|---|
| 131 | |
| 103 | |
| 58 | |
| 39 | |
| 31 |