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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Show Previous month value based on month order.

I would like to ask about the DAX I saw online (see script below). The context is that I'm having trouble showing the previous month's because the data have gaps, these are the months with no data on the dataset (Mar 2022, May2022, & Jun 2022). I would like to ask for help to make the value show based on the month order not based on the date with data on dataset. I will attach the snips below and also the script I found. Thanks.
Target Output: ($1535) should reflect on the second column of Mar 2022 not in Apr 2022
Capture.PNG

1st col.= Report Month

2nd col.= Current Month Value

3rd col.= Previous Month Value 

 

This is the code

previous result =
var period_context = MAX (data [period])

var previous_period =
CALCULATE(
   MAX (data [period]),
   FILTER(
      ALL (data [period]),
      data [period] <period_context &&
      SUM (data [value]) <> BLANK ()
   )
)

var previous_month_value =
CALCULATE(
   SUM (data [value]),
   FILTER(
      ALL (data [period]),
      data [period] = previous_period
   )
)

Return
if(
   ISINSCOPE (data [period]),
   previous_month_value
)
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Add a calendar table to your data model.

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Add a calendar table to your data model.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.