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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Vinayak1991
New Member

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
Solution Sage
Solution Sage

@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
Solution Sage
Solution Sage

@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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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