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
Ling_wen97
New Member

Comparing lastest 3 months with the previous 3 months.

Hi all,

Can anyone help with this formula in Power BI DAX please.

Ling_wen97_1-1669778629835.png

 

Ling_wen97_0-1669778614149.png

The result I need is in precentage.

Thanks,

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @Ling_wen97 ,

 

Try formula like below:

M =
VAR cur =
    MONTH ( MAX ( test[Date] ) )
VAR pre1 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), 0 ) )
VAR pre2 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), -2 ) )
VAR nex1 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), -3 ) )
VAR nex2 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), -5 ) )
VAR per =
    CALCULATE (
        SUM ( test[Order Qty] ),
        FILTER ( ALL ( test ), cur <= pre1 && cur >= pre2 )
    )
VAR nex =
    CALCULATE (
        SUM ( test[Order Qty] ),
        FILTER ( ALL ( test ), cur <= nex1 && cur >= nex2 )
    )
RETURN
    DIVIDE ( per, nex )

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

View solution in original post

3 REPLIES 3
v-henryk-mstf
Community Support
Community Support

Hi @Ling_wen97 ,

 

Try formula like below:

M =
VAR cur =
    MONTH ( MAX ( test[Date] ) )
VAR pre1 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), 0 ) )
VAR pre2 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), -2 ) )
VAR nex1 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), -3 ) )
VAR nex2 =
    MONTH ( EOMONTH ( MAX ( test[Date] ), -5 ) )
VAR per =
    CALCULATE (
        SUM ( test[Order Qty] ),
        FILTER ( ALL ( test ), cur <= pre1 && cur >= pre2 )
    )
VAR nex =
    CALCULATE (
        SUM ( test[Order Qty] ),
        FILTER ( ALL ( test ), cur <= nex1 && cur >= nex2 )
    )
RETURN
    DIVIDE ( per, nex )

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


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

Ling_wen97
New Member

This will be the sameple data for example
Named table - Test

Ling_wen97_0-1669786968403.png

 

FreemanZ
Super User
Super User

DAX depends on context/scenario heavily, you will get your solution faster if you could provide some sample data, ideally with named table and columns.

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