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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Vinayak1991
Regular Visitor

Replacing subtotal values with another formula

I have month wise data of certain expenses. I have plotted this data in Matrix as expenses in rows and months in columns. I have already activated columns subtotal from visual format which is giving me total value of expense for all the months, but I need only difference of last two months in subtotal column or I need one additional column at the end of all months, showing difference of last two months  I have attached images for both currently I am having and image for what I need, Does it possible in DAX or another function??Data currently availableData currently availableFormat I needFormat I need

1 ACCEPTED SOLUTION
tharunkumarRTK
Super User
Super User

@Vinayak1991 

You can follow this pattern: 

LastTwoMonhsdiff = 
Var __relation = SUMMARIZE(ALL(financials), financials[Month Name], financials[Month Number]) 
Var __maxMonthNum = MAXX(__relation, financials[Month Number]) 
Var __lastToLastMonth = SUMX(FILTER( __relation, financials[Month Number] = __maxMonthNum - 1), CALCULATE(SUM(financials[ Sales])))
Var __lastMonth = SUMX(FILTER( __relation, financials[Month Number] = __maxMonthNum ) , CALCULATE(SUM(financials[ Sales]))) 
RETURN IF(HASONEVALUE(financials[Month Name]), CALCULATE(SUM(financials[ Sales])), __lastMonth - __lastToLastMonth  ) 



Screenshot 2024-03-28 at 5.04.16 PM.png

 

I think the new visual calculations feature will make this pattern quiet simple. 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun

 

View solution in original post

1 REPLY 1
tharunkumarRTK
Super User
Super User

@Vinayak1991 

You can follow this pattern: 

LastTwoMonhsdiff = 
Var __relation = SUMMARIZE(ALL(financials), financials[Month Name], financials[Month Number]) 
Var __maxMonthNum = MAXX(__relation, financials[Month Number]) 
Var __lastToLastMonth = SUMX(FILTER( __relation, financials[Month Number] = __maxMonthNum - 1), CALCULATE(SUM(financials[ Sales])))
Var __lastMonth = SUMX(FILTER( __relation, financials[Month Number] = __maxMonthNum ) , CALCULATE(SUM(financials[ Sales]))) 
RETURN IF(HASONEVALUE(financials[Month Name]), CALCULATE(SUM(financials[ Sales])), __lastMonth - __lastToLastMonth  ) 



Screenshot 2024-03-28 at 5.04.16 PM.png

 

I think the new visual calculations feature will make this pattern quiet simple. 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun

 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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