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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register now.

Reply
Mido99
New Member

Calculate difference in cost based on combined query results

hi all,

 

i have a table in Power BI that is the result of a combined query (3 tables), which means i have a column with 3 different project IDs (4010 = current project, 3844 = previous month's project, 3653 = baseline)

 

i have another column called "actual cost" and what i would like to do is add a calculated column that calculates for each row the difference between the actual cost in ID 4010 vs ID 3844, based on the denominator activity ID or name.

 

how would i go about doing this?

 

thank you in advance

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Mido99 

Thanks for reaching out to us.

My suggestion is to find the values where project ID=4010 and 3653 by denominator activity ID, and then calculate the difference. For example,

sample data

vxiaotang_0-1664245712695.png

Column = 
var _4010=MAXX(FILTER(ALL('Table'),'Table'[denominator activity ID]=EARLIER('Table'[denominator activity ID]) && [project IDs]=4010),[actual cost])
var _3844=MAXX(FILTER(ALL('Table'),'Table'[denominator activity ID]=EARLIER('Table'[denominator activity ID]) && [project IDs]=3844),[actual cost])
return _3844-_4010

result

vxiaotang_1-1664245736878.png

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @Mido99 

Thanks for reaching out to us.

My suggestion is to find the values where project ID=4010 and 3653 by denominator activity ID, and then calculate the difference. For example,

sample data

vxiaotang_0-1664245712695.png

Column = 
var _4010=MAXX(FILTER(ALL('Table'),'Table'[denominator activity ID]=EARLIER('Table'[denominator activity ID]) && [project IDs]=4010),[actual cost])
var _3844=MAXX(FILTER(ALL('Table'),'Table'[denominator activity ID]=EARLIER('Table'[denominator activity ID]) && [project IDs]=3844),[actual cost])
return _3844-_4010

result

vxiaotang_1-1664245736878.png

 

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Mido99 , if you need a column

Cost 4010   =

sumx(filter(Table, Table[Project ID]= 4010  && Table[Activity ID] = earlier(Table[Activity ID] ) ), Table[Cost])

 

cost 3844 =

sumx(filter(Table, Table[Project ID]= 3844 && Table[Activity ID] = earlier(Table[Activity ID] ) ), Table[Cost])

 

if you need measure

calculate(sum(Table[Cost]), Table[Project ID]= 3844 )

 

or

 

calculate(sum(Table[Cost]), Table[Project ID]= 4010)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
May PBI 25 Carousel

Power BI Monthly Update - May 2025

Check out the May 2025 Power BI update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

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