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! Learn more

Reply
Fusilier2
Helper V
Helper V

Help with prior month measure

Hi,

Hopefully somebody can suggest a quick fix for this.

I currently have this measure:

Apprentices Current Month =
CALCULATE(
    SUM(HR_data[No. of Apprentice]),
    FILTER(
        HR_data,
        HR_data[Period]=MAX(HR_data[Period])

))
 
It returns the data for the latest month in my table.
I'm trying to create a similar measure that will always return the value for the previous month.
I've tried adding -1 to the end of the max statement:
Apprentices Current Month =
CALCULATE(
    SUM(HR_data[No. of Apprentice]),
    FILTER(
        HR_data,
        HR_data[Period]=MAX(HR_data[Period]-1)
 
But that gives me a 'MAX function only accepts a column reference as an argement' error.
Can anybody suggest what I should do to fix this?
 
 
Thanks
 
 
1 ACCEPTED SOLUTION

Thank you for your help.

I shall investigate date dimension tables when I get some more time.

In the meantime, your suggestion didn't work. It returned nil.

However I got this to work:

Apprentices Prior month  =
CALCULATE(
    SUM(HR_data[No. of Apprentice]),
    FILTER(
        ALL(HR_data[Period]),
        HR_data[Period]=EOMONTH(MAX(HR_data[Period]),-1)
        )
    )
  Which seems OK for me now.      

 

View solution in original post

6 REPLIES 6
pankajnamekar25
Super User
Super User

Hello @Fusilier2 

 

You can try this

Apprentices Previous Month =

CALCULATE(

    SUM(HR_data[No. of Apprentice]),

    FILTER(

        HR_data,

        HR_data[Period] = EDATE(MAX(HR_data[Period]), -1)

    )

)

 

Thanks,
 Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

danextian
Super User
Super User

Hi @Fusilier2 

 

That is because -1 is enclosed in MAX as well. Try this:

CALCULATE (
    SUM ( HR_data[No. of Apprentice] ),
    FILTER ( HR_data, HR_data[Period] = MAX ( HR_data[Period] ) - 1 )
)

 

This measure works if there isn't a filter coming from Period. For example, if you select Period 1, the measure will return blank as DAX sees Period 1 and not Period - 1 . You can change your measure to the following

CALCULATE (
    SUM ( HR_data[No. of Apprentice] ),
    FILTER ( ALL ( HR_data, HR_data[Period] ) = MAX ( HR_data[Period] ) - 1 )
)

 This aside, I would start using a dedicate date dimension table to simply time intelligence calculations.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thank you for your help.

I shall investigate date dimension tables when I get some more time.

In the meantime, your suggestion didn't work. It returned nil.

However I got this to work:

Apprentices Prior month  =
CALCULATE(
    SUM(HR_data[No. of Apprentice]),
    FILTER(
        ALL(HR_data[Period]),
        HR_data[Period]=EOMONTH(MAX(HR_data[Period]),-1)
        )
    )
  Which seems OK for me now.      

 

Hi @Fusilier2,

 

I'm glad you found a solution and resloved  the query. Thank you very much for sharing here.

Kindly mark your reply as the accepted solution so that others in the community can find it quickly.

 

Thankyou for connecting with Microsoft Community Forum.

Hi @Fusilier2 ,

 

Since we haven't heard back from you yet, I'd like to confirm if you've successfully resolved this issue or if you need further help?
If you've already resolved the issue, you can mark the helpful reply as a "solution" so others know that the question has been answered and help other people in the community.

Thank you again for your cooperation!

 

Ritaf1983
Super User
Super User

Hi @Fusilier2 
You should use the dim date table in your model , it will help use time intellegence functions.

Please refer to the linkded video:
https://www.youtube.com/watch?v=-gEhRzdhKro

For more specific suggestions Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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.

Top Solution Authors