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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.