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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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