Skip to main content
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Krisvenkata11
Frequent Visitor

Calculate variance between 2 weeks

 

I am looking to calculate the dax query  some thing like below(Measure or column). Variance should be the output which is difference the weeks like diff between week2 and week1 is -1

WeekSalesVariance
166
25-1
383
47-1
54-3
63-1
72-1
80-2
91010
10122
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Krisvenkata11 ,

 

You can create a measure like below to calculate variance between 2 weeks :

 

Variance =
VAR cur_week =
    MIN ( Sheet1[Week] )
VAR previous_week =
    CALCULATE (
        MAX ( Sheet1[Week] ),
        FILTER ( ALL ( Sheet1 ), Sheet1[Week] < cur_week )
    )
VAR cur_sales =
    MIN ( Sheet1[Sales] )
VAR previous_sales =
    CALCULATE (
        MAX ( Sheet1[Sales] ),
        FILTER ( ALL ( Sheet1 ), Sheet1[Week] = previous_week )
    )
RETURN
    cur_sales - previous_sales

 

vbinbinyumsft_0-1657527831464.png

 

 

Best regards,
Community Support Team_ Binbin Yu
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

2 REPLIES 2
Jos_Woolley
Solution Sage
Solution Sage

Hi,

As a measure:

MyMeasure =
VAR ThisWeek =
    MIN( 'Table'[Week] )
VAR PreviousWeek =
    CALCULATE(
        MAX( 'Table'[Week] ),
        FILTER( ALLSELECTED( 'Table' ), 'Table'[Week] < ThisWeek )
    )
VAR ThisSales =
    MIN( 'Table'[Sales] )
VAR PreviousSales =
    CALCULATE(
        MIN( 'Table'[Sales] ),
        FILTER( ALLSELECTED( 'Table' ), 'Table'[Week] = PreviousWeek )
    )
RETURN
    ThisSales - PreviousSales

Regards

Anonymous
Not applicable

Hi @Krisvenkata11 ,

 

You can create a measure like below to calculate variance between 2 weeks :

 

Variance =
VAR cur_week =
    MIN ( Sheet1[Week] )
VAR previous_week =
    CALCULATE (
        MAX ( Sheet1[Week] ),
        FILTER ( ALL ( Sheet1 ), Sheet1[Week] < cur_week )
    )
VAR cur_sales =
    MIN ( Sheet1[Sales] )
VAR previous_sales =
    CALCULATE (
        MAX ( Sheet1[Sales] ),
        FILTER ( ALL ( Sheet1 ), Sheet1[Week] = previous_week )
    )
RETURN
    cur_sales - previous_sales

 

vbinbinyumsft_0-1657527831464.png

 

 

Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
November Fabric Update Carousel

Fabric Monthly Update - November 2025

Check out the November 2025 Fabric 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.

Users online (25)