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
JulietZhu
Helper IV
Helper IV

DAX help for last 13 month amount with single data filter

I used the following DAX to calculate last 13 month amount,

 

Amt(last n months) =
VAR MaxFactDate =
    CALCULATE ( MAX ( Transactions[TransactionDate]), ALL ( 'Date') )
VAR FDate =
    ENDOFMONTH ( 'Date'[Date] )
VAR Edate =
    EDATE ( FDate, -13 )
RETURN
    IF (
MaxFactDate <= MAX ( 'Date'[Date] )
&& MaxFactDate > Edate,
        CALCULATE ( Transactions[Amount_CurrentM] , ALL ( 'Date') )
    )

But , when I choose Sep, June and April, it gives 14 month data. Oct, Aug, July,May March etc give correct 13 months.

Don't know why. Anyboday help it out. Thanks

 

1.PNG

 

 

Dummy data link,

https://1drv.ms/u/s!AlYpYKwSuOKxhFKUw4W_d_r8VIFu

 

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @JulietZhu

Modify your formula with the following

Amt(last n months) = 
VAR MaxFactDate =
    CALCULATE ( MAX ( Transactions[TransactionDate]), ALL ( 'Date') ) 
VAR FDate =
    ENDOFMONTH ( 'Date'[Date] ) 
VAR Edate =
    EDATE ( FDate, -13 ) 
VAR Edate1=IF(DAY(FDate)=30,Edate+1,IF(DAY(FDate)=28,Edate+3,IF(DAY(FDate)=29,Edate+2,Edate))) RETURN IF ( MaxFactDate <= MAX ( 'Date'[Date] ) && MaxFactDate > Edate1, CALCULATE ( Transactions[Amount_CurrentM] , ALL ( 'Date') ) )

14.png

 

Best Regards

Maggie

View solution in original post

2 REPLIES 2
v-juanli-msft
Community Support
Community Support

Hi @JulietZhu

Modify your formula with the following

Amt(last n months) = 
VAR MaxFactDate =
    CALCULATE ( MAX ( Transactions[TransactionDate]), ALL ( 'Date') ) 
VAR FDate =
    ENDOFMONTH ( 'Date'[Date] ) 
VAR Edate =
    EDATE ( FDate, -13 ) 
VAR Edate1=IF(DAY(FDate)=30,Edate+1,IF(DAY(FDate)=28,Edate+3,IF(DAY(FDate)=29,Edate+2,Edate))) RETURN IF ( MaxFactDate <= MAX ( 'Date'[Date] ) && MaxFactDate > Edate1, CALCULATE ( Transactions[Amount_CurrentM] , ALL ( 'Date') ) )

14.png

 

Best Regards

Maggie

@v-juanli-msft, it works. Thanks

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors