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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
metcala
Helper III
Helper III

Difference between values for selected slicer date and previous month

Hi

 

I have the following table.

 

MonthProjectWeek CommencingRoleHours
1/1/24A1/4/24Analyst10
1/1/24A1/4/24Project Manager5
1/1/24B1/4/24Analyst25
1/1/24B1/4/24Project Manager20
1/1/24A8/4/24Analyst10
1/1/24A8/4/24Project Manager5
1/1/24B8/4/24Analyst25
1/1/24B8/4/24Project Manager20
1/2/24A1/4/24Analyst15
1/2/24A1/4/24Project Manager10
1/2/24B1/4/24Analyst20
1/2/24B1/4/24Project Manager20
1/2/24A8/4/24Analyst15
1/2/24A8/4/24Project Manager5
1/2/24B8/4/24Analyst25
1/2/24B8/4/24Project Manager25

 

I am looking to get the following results showing the difference from the month selected vs the previous month

 

Slicer: Month e.g. 1/2

 

ProjectRole1/4/248/4/24
AAnalyst55
AProject Manager50
BAnalyst-50
BProject Manager05

 

This is my current thinking but just can't seem to get it working....

 

 

Month Difference = 
VAR SelectedMonth = MAX('Supply'[Month])
VAR PriorMonth = EOMONTH(SelectedMonth,-2)+1
VAR SupplySelectedMonth =
   CALCULATE(
      SUM('Supply'[Hours]),
      'Supply'[Month] = SelectedMonth
   )
VAR SupplyPriorMonth =
   CALCULATE(
      SUM('Supply'[Hours]),
      'Supply'[Month] = PriorMonth
   )
RETURN
IF(
   ISBLANK(SupplySelectedMonth),
   BLANK(),
   SupplySelectedMonth - SupplyPriorMonth
)

 

 

Any help would be much appreciated!

1 ACCEPTED SOLUTION
Irwan
Super User
Super User

Hello @metcala 

 

please check if this acomodate your need.

Irwan_0-1720479660165.png

 

Create new measure as following DAX

Month Difference =
var _SelectedMonth = SELECTEDVALUE('Supply'[Month]) //find selected date
var _PriorMonth = EOMONTH(_SelectedMonth,-1) //define previous date of selected date
var _SupplySelectedMonth = CALCULATE(SUM('Supply'[Hours]),EOMONTH('Supply'[Month],0)=EOMONTH(_SelectedMonth,0)) //calculate sum of selected date
var _SupplyPriorMonth = CALCULATE(SUM('Supply'[Hours]),EOMONTH('Supply'[Month],-1)=EOMONTH(_PriorMonth,-1)) //calculate sum of previous date
Return
IF(
    ISBLANK(_SupplySelectedMonth),
    BLANK(),
    _SupplySelectedMonth-_SupplyPriorMonth
)
Irwan_1-1720480227133.png

 

From your DAX, it looks like the _SelectedMonth will be always maximum date since you are using MAX('Supply'[Month]), but you want to see value difference from any selected date (not only maximum date). However if my assumption is wrong, then please adjust the DAX into your preference SelectedMonth.

 

Hope this will help you.

Thank you.

View solution in original post

1 REPLY 1
Irwan
Super User
Super User

Hello @metcala 

 

please check if this acomodate your need.

Irwan_0-1720479660165.png

 

Create new measure as following DAX

Month Difference =
var _SelectedMonth = SELECTEDVALUE('Supply'[Month]) //find selected date
var _PriorMonth = EOMONTH(_SelectedMonth,-1) //define previous date of selected date
var _SupplySelectedMonth = CALCULATE(SUM('Supply'[Hours]),EOMONTH('Supply'[Month],0)=EOMONTH(_SelectedMonth,0)) //calculate sum of selected date
var _SupplyPriorMonth = CALCULATE(SUM('Supply'[Hours]),EOMONTH('Supply'[Month],-1)=EOMONTH(_PriorMonth,-1)) //calculate sum of previous date
Return
IF(
    ISBLANK(_SupplySelectedMonth),
    BLANK(),
    _SupplySelectedMonth-_SupplyPriorMonth
)
Irwan_1-1720480227133.png

 

From your DAX, it looks like the _SelectedMonth will be always maximum date since you are using MAX('Supply'[Month]), but you want to see value difference from any selected date (not only maximum date). However if my assumption is wrong, then please adjust the DAX into your preference SelectedMonth.

 

Hope this will help you.

Thank you.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.