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

Compare rows from other table to make calculated column in first table

Hi, 

 

I have two tables, one with accounts, and one with expenses. In the table with accounts I have an ID, which is linked to the expense table, and I have an account Name, a status and I would like a calculated column which should determine whether or not the account is ready to be closed. 

 

Table with accounts: 

Id   Account   Status   ShouldClose   
1AActive0
2BCompleted0
3CCompleted1
4DCompleted1
5EClosed0

 

This calculated column, marked with orange should be calculated based on the status and on the second table with expenses. If the current Actual and Posted Revenue and Expense are equal to each other, and the Account = Completed, then the flag should be 1. 

 

AccountID    Type   IsCurrent   Rev   Exp   
1Actual1500100
1Posted1500100
2Actual1600150
2Posted160050
3Actual010001000
3Posted0500500
3Actual11200400
3Posted11200400
4Actual11600800
4Posted11600800
5Actual1900100
5Posted1900100

 

E.g. for AccountID 3: 

Current Rev: 

Actual 1200 - Posted 1200 = 0

Current Exp: 

Actual 400 - Posted 400 =

 

Here the flag should be 1, because the Account is Completed. 

 

E.g. for Account 2: 

Current Rev: 

Actual 600 - Posted 600 = 0

Current Exp: 

Actual 150 - Posted 50 = 100

 

Here the flag should be 0, since both are not equal to 0. 

 

I hope this makes sense, and that you can help me 🙂 

1 REPLY 1
amitchandak
Super User
Super User

@C-Jac , Try a new column in Table1

new column =
var _1 = sumx(filter(Table2, Table2[IsCurrent] =1 && Table2[AccountID] = Table1[ID] && Table1[Type] ="Actual"), Table2[REV]+ Table2[Exp])
var _2 = sumx(filter(Table2, Table2[IsCurrent] =1 && Table2[AccountID] = Table1[ID] && Table1[Type] ="Posted"), Table2[REV]+ Table2[Exp])
return
if(_1 =_2 ,1,0)

Helpful resources

Announcements
Join Arun Ulag at MPPC23

Join Arun Ulag at MPPC23

Get a sneak peek into this year's Power Platform Conference Keynote.

PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Top Solution Authors
Top Kudoed Authors