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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
BarbaraK
New Member

DAX Calculated Column needed in Query for join

I have query data "Weekly Sales" that looks a bit like this (changed for confidentiality):

 

CodeDescQtyIndex
 Debtor: XYZ Debtor 1
1010Product 1122
1020Product 233
1030Product 344
 Debtor: PRT Debtor 5
1010Product 1446
1020Product 2667
1030Product 338

 

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:

LocationCodeDescQtyIndex
Debtor: XYZ Debtor Debtor: XYZ Debtor 1
Debtor: XYZ Debtor1010Product 1122
Debtor: XYZ Debtor1020Product 233
Debtor: XYZ Debtor1030Product 344
Debtor: PRT Debtor Debtor: PRT Debtor 5
Debtor: PRT Debtor1010Product 1446
Debtor: PRT Debtor1020Product 2667
Debtor: PRT Debtor1030Product 338

 

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!

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@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.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@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?

Screen Shot.png

@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.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.