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
Anonymous
Not applicable

Get variation between two values for only the last date


Hello,

 

I have a table with two value A & B. each them is group by data and segment.

 

I have to get the variation between the values A & B between the different Quarter and displayed only for the current date.

i made this DAX query but does not work correcly:


VariationTest =
VAR __mostRecentVisibleDate =
CALCULATE ( MAX ( Calendrier[Date] ); ALLSELECTED ( 'Calendrier' ) )
VAR __previousVisibleDate =
PREVIOUSQUARTER(Calendrier[Max Date])
VAR A = [sumamount]
VAR B =
CALCULATE (
[sumamount];
ALLSELECTED ( 'Calendrier' );
Calendrier[Date] = __previousVisibleDate
)
VAR __variancePercent =
DIVIDE ( B - A ; A )
RETURN
IF (
MAX ( Calendrier[Date] ) = __mostRecentVisibleDate;
__variancePercent
)

As PREVIOUSQUARTER does not take directly  __mostRecentVisibleDate, I create Max Date column with 

Max Date = MAX(Calendrier[Date])

 

 

Can someone help on this please.

 

Thank you in advance

 

 

2 REPLIES 2
Anonymous
Not applicable

Thank you very much, I will try that

 

Anonymous
Not applicable

Hi @Anonymous 

 

Please try the following Dax:

VariationTest =
VAR __mostRecentVisibleDate = 
    MAXX(
        ALLSELECTED('Calendrier'),
        'Calendrier'[Date]
    )
VAR __startOfQuarter = 
    STARTOFQUARTER(__mostRecentVisibleDate)
VAR __startOfPreviousQuarter = 
    STARTOFQUARTER(
        EDATE(__mostRecentVisibleDate, -3)
    )
VAR CurrentQuarterAmount = 
    CALCULATE(
        [sumamount],
        DATESBETWEEN(
            'Calendrier'[Date],
            __startOfQuarter,
            __mostRecentVisibleDate
        )
    )
VAR PreviousQuarterAmount = 
    CALCULATE(
        [sumamount],
        DATESBETWEEN(
            'Calendrier'[Date],
            __startOfPreviousQuarter,
            EDATE(__startOfQuarter, -1)
        )
    )
VAR __variancePercent = 
    DIVIDE(
        PreviousQuarterAmount - CurrentQuarterAmount, 
        CurrentQuarterAmount
    )
RETURN
    IF(
        MAX('Calendrier'[Date]) = __mostRecentVisibleDate,
        __variancePercent,
        BLANK()
    )

 

 

 

 

 

 

Best Regards,

Jayleny

 

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

 

 

 

 

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.