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
JustinDoh1
Post Prodigy
Post Prodigy

How to subtract one more month to DATEDIFF result (only if total is 0 or greater than 0)?

I have following measure:

 

ForecastMonths = DATEDIFF(
                                                FIRSTDATE ('Table'[Survey Date]),
                                                LASTDATE ('Calendar'[Month Year]),
                                                MONTH
                                              )
 
I am trying to adjust the result (which comes in number of month) to one more/less month.
 
JustinDoh1_0-1761683460657.png

 

I would like the result to be either 91 or 89.

 
How do I go about doing it?
 
Thanks for help.
 

 

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@JustinDoh1 not sure what you are trying to achieve, when you add or subtract:

 

ForecastMonths = DATEDIFF(
                                                FIRSTDATE ('Table'[Survey Date]),
                                                LASTDATE ('Calendar'[Month Year]),
                                                MONTH
                                              ) + 1 // or -1


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
Kedar_Pande
Super User
Super User

@JustinDoh1 

 

ForecastMonths =
VAR Diff = DATEDIFF(
FIRSTDATE('Table'[Survey Date]),
LASTDATE('Calendar'[Month Year]),
MONTH
)
RETURN
IF(Diff >= 0, Diff - 1, Diff)

 

If this answer helped, please click Kudos or mark as Solution.
-Kedar
LinkedIn: https://www.linkedin.com/in/kedar-pande

parry2k
Super User
Super User

@JustinDoh1 sure here it is, change the condition as per your needs

 

ForecastMonths = 
VAR __Months = 
DATEDIFF(
    FIRSTDATE ('Table'[Survey Date]),
    LASTDATE ('Calendar'[Month Year]),
    MONTH
)
RETURN
IF ( __Months >= 0, __Months - 1, __Months )

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@JustinDoh1 not sure what you are trying to achieve, when you add or subtract:

 

ForecastMonths = DATEDIFF(
                                                FIRSTDATE ('Table'[Survey Date]),
                                                LASTDATE ('Calendar'[Month Year]),
                                                MONTH
                                              ) + 1 // or -1


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k Thank you and sorry.

I guess I need to use  -1.

 

Can I ask you one more question?

How can I wrap so that this condition only applies if value is 0 or greater than 0 so that there is no -1?

I guess I am trying to use IF statement for the result..  Thanks.

djurecicK2
Super User
Super User

Hi @JustinDoh1 ,

 You can use EDATE on the LASTDATE to achieve this:

https://learn.microsoft.com/en-us/dax/edate-function-dax

 

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.