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
jk8979356
Regular Visitor

How do I reference a specific cell value from a 2nd table inside of a formula on a different table?

I have a table that has the following formula:

 

= Table.AddColumn(#"Changed Type2", "Qty Forecast", each if [Quantity] <= 0 then [Quantity] else ([Quantity] / (List.Sum(#"Changed Type2"[Amount]) / 19950000)))

 

This formula works, but rather than have a hard coded value of 1995000, I want to use a variable value that is pulled from another table in the Power Query Editor. 

 

The 2nd table is named "forecast" and has the value in row 1 of column2.

 

What is the exact M script code to replace the hardcoded 19950000 value with a script that pulls the value from the "forecast" table, row 1, column2? Both tables are in the same Power Query Editor but are not merged queries. 

1 ACCEPTED SOLUTION

@jk8979356 , so you may use

 

= Table.AddColumn(#"Changed Type2", "Qty Forecast", each if [Quantity] <= 0 then [Quantity] else ([Quantity] / (List.Sum(#"Changed Type2"[Amount]) / #"2020forecast"{0}[column2])))

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

8 REPLIES 8
AnkitKukreja
Super User
Super User

Hi @jk8979356 

 

Please try this, you should get that column from your forecast table to your current table and then you can use it in your formula.

 

Please refer this.

https://community.powerbi.com/t5/Desktop/M-Script-Help-custom-column-referencing-another-table/td-p/...

 

Thanks,

Ankit

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
https://topmate.io/ankit_kukreja

I have read that discussion, but don't understand the exact M code I need in my situation. I'm fine if I need to first bring in the value from the forecast table into the sales table, but what exact M code do I use to do this? Since there is only a single value in the forecast table and I am not using a match of any kind, but rather using 1 single value for all rows, what code do I use to add the forecast value into my sales table as a new column?

CNENFRNL
Community Champion
Community Champion

Hi, @jk8979356 , you may use 

= Table.AddColumn(#"Changed Type2", "Qty Forecast", each if [Quantity] <= 0 then [Quantity] else ([Quantity] / (List.Sum(#"Changed Type2"[Amount]) / forecase[column2]{0})))

or equally

= Table.AddColumn(#"Changed Type2", "Qty Forecast", each if [Quantity] <= 0 then [Quantity] else ([Quantity] / (List.Sum(#"Changed Type2"[Amount]) / forecase{0}[column2])))

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Thanks for the help. When I add that I get the following error:

 

jk8979356_0-1602392669780.png

If I open it in the Advanced Editor, it doesn't show the full error:

jk8979356_1-1602392725155.png

Any ideas?

 

@jk8979356 , what's the name of the query where you extract the number?


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

The query name for I extract the number is "2020forecast"

jk8979356_0-1602422404147.png

 

@jk8979356 , so you may use

 

= Table.AddColumn(#"Changed Type2", "Qty Forecast", each if [Quantity] <= 0 then [Quantity] else ([Quantity] / (List.Sum(#"Changed Type2"[Amount]) / #"2020forecast"{0}[column2])))

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

That worked. You are awesome! Thank you so much for your help!

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.