cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Create a Calculated Column from Different Tables

Hi ,

 

I can’t work out how to create a calculated column using 2 columns from different tables in the formula.

 

I’m trying to create a calculated column ‘Z’ using a simple formula: X – Y

 

Column X is in table 1

Column Y is in table 2

 

When creating Z in table 1, it does not see columns from any other tables. There is a relationship between both tables which I have checked is still there.

 

This is very strange, I have created calculated columns using column data from 2 separate tables many times before and never had any problems.

 

Any ideas?

 

 

Thanks,

 

Greg

1 ACCEPTED SOLUTION
Microsoft
Microsoft

@GCGradwell

 

Based on my understanding, it depends on the relationship.

 

If 1:1, below formula should work.

calculated column =
table1[X] - RELATED ( table2[Y] )

If 1:many, the following formula should work.

calculated column =
oneTable[X]
    - CALCULATE ( SUM ( manyTable[Y] ), ALLEXCEPT ( manyTable, Table10[linkedCol] ) )

View solution in original post

9 REPLIES 9
Microsoft
Microsoft

@GCGradwell

 

Based on my understanding, it depends on the relationship.

 

If 1:1, below formula should work.

calculated column =
table1[X] - RELATED ( table2[Y] )

If 1:many, the following formula should work.

calculated column =
oneTable[X]
    - CALCULATE ( SUM ( manyTable[Y] ), ALLEXCEPT ( manyTable, Table10[linkedCol] ) )

View solution in original post

What if it's a Many to many relationship? 

I'm trying to do a similar thing but can't get the formula you provided to work.

 

I have two tables and want to subtract Column A from Table 1 from Column B from Table 2.  There is a relationship between the two tables via a common ID. 

 

 

The relationship is one to many whereby the value being subtracted is the 'one table' and the one from which data is being subtracted from, is the 'many table'.

 

The data is in date format.

 

i.e 05/03/2017 - 03/03/2017 = 2

 

Any help appreciated.

 

Thanks

Hi ,

 

i am trying to create a calculated column using 2 different tables. i am getting error.

 

My query:

 

=if(table1[column1] = "abc"  || table1[column1]  =  "bcd", "Others",  if( table1[column1]  ="xyz" ,  if( table2[column2]  = "pqr", "Oman", if( table2[column2] = "que", "hyz", "ecc"))))

 

Error:

 

column 'column2' in 'table2' cannot be found or may not be used in this expression.

 

please suggest proper syntax.

 

thank you.

 

 

 

Hi,

 

Share the link from where i can download your file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

I am new to Power BI .  Can I use data in tables to calculate more data?

 

My example is: I have Forecasted Product sales for 2 weeks. Prod 1, 100 units, Prod 2, 200 units.

 

I have a table with the Sales Mix % by Week, Week 1, 75%, week 2, 25%

 

Can I calculate out these to two table to create a new table with forecasted sales by week.

eg

Week1, Prod1, 75 units

Week2, Prod1, 25 units

Week1, Prod2, 150 units

Week2, Prod2, 50 units

 

I am calculating this in excel and then loading to power BI. 

 

Thanks

Sam

Hi @IanSamTaylor,

 

See the Data table in this file.

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Memorable Member
Memorable Member

as someone coming to Power BI from databases - my immediate question of your post is - where is the unique ID (key) field for these two tables?  In order to any math one must know which row's value to use on both sides......

 

Perhaps that's a given - just thought I would throw that in....   in which case your expression would be involving Related Table....

 

 

 

 

 

 

www.CahabaData.com

You are asking very general questions, so it is hard to know what you are trying to do, or why.  My experience is that most calculated columns that new users try to build are completetly un-necessary and probably worse still - it normally is the wrong approach.  Read my article here, then see if you can do what you want with measures.

 

http://exceleratorbi.com.au/calculated-columns-vs-measures-dax/



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors