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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
KD1
New Member

Subtract previous average from current average

Hi Dax community,

 

I would like to calculate the difference in average satisfaction between the current and previous period but I could not figure out a DAX.  I tried indexing and using the earlier function to no avail.  I kept getting an error message with the earlier function. Is there a workaround?

 

Example Data

Survey PeriodIDSatisfaction
Jan-2014
Jan-2024
Jan-2033
Jan-2044
Jan-2052
Jul-2013
Jul-2023
Jul-2031
Jul-2041
Jan-2112
Jan-2121
Jan-2132
Jul-2114
Jul-2123
Jul-2135
Jul-2143
Jan-2211
Jan-2225
Jan-2235
Jan-2244
Jan-2252

 

Result

Survey PeriodCurrent PreviousDifference
Jan-203.4nullnull
Jul-203.53.40.1
Jan-2133.5-0.5
Jul-213.2530.25
Jan-2243.250.75
1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @KD1,

 

You may try this solution.

1 Create a Calculated column

Date =
VAR Month_ =
    SWITCH (
        LEFT ( 'Table'[Survey Period], 3 ),
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6,
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12
    )
VAR Year_ =
    2000 + RIGHT ( 'Table'[Survey Period], 2 )
RETURN
    DATE ( Year_, Month_, 1 )

 

2 Create the following Measures

Current = CALCULATE(AVERAGE('Table'[Satisfaction]),FILTER(ALL('Table'),'Table'[Date]<=MAX('Table'[Date])))

 

Previous = CALCULATE([Current],FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])))

 

Difference = IF(ISBLANK([Previous]),BLANK(),[Current]-[Previous])

 

Then, the result looks like this.

vcazhengmsft_0-1651554675920.png

 

Also, attach the pbix file as reference. Hope it helps.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

View solution in original post

2 REPLIES 2
v-cazheng-msft
Community Support
Community Support

Hi @KD1,

 

You may try this solution.

1 Create a Calculated column

Date =
VAR Month_ =
    SWITCH (
        LEFT ( 'Table'[Survey Period], 3 ),
        "Jan", 1,
        "Feb", 2,
        "Mar", 3,
        "Apr", 4,
        "May", 5,
        "Jun", 6,
        "Jul", 7,
        "Aug", 8,
        "Sep", 9,
        "Oct", 10,
        "Nov", 11,
        "Dec", 12
    )
VAR Year_ =
    2000 + RIGHT ( 'Table'[Survey Period], 2 )
RETURN
    DATE ( Year_, Month_, 1 )

 

2 Create the following Measures

Current = CALCULATE(AVERAGE('Table'[Satisfaction]),FILTER(ALL('Table'),'Table'[Date]<=MAX('Table'[Date])))

 

Previous = CALCULATE([Current],FILTER(ALL('Table'),'Table'[Date]<MAX('Table'[Date])))

 

Difference = IF(ISBLANK([Previous]),BLANK(),[Current]-[Previous])

 

Then, the result looks like this.

vcazhengmsft_0-1651554675920.png

 

Also, attach the pbix file as reference. Hope it helps.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let me know. Thanks a lot!

 

Best Regards,

Community Support Team _ Caiyun

amitchandak
Super User
Super User

@KD1 , Create a new tbale with distinct Survey and period and then try meausre like these

 

This Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Period]=max(Period[Period]) && period[Survey] =max(period[Survey] ) ))
Last Period = CALCULATE(sum('Table'[Qty]), FILTER(ALL(Period),Period[Period]=max(Period[Period])-1 && period[Survey] =max(period[Survey] ) ))

 

 

period table = summarize(Table, Table[Survey], Table[Period])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.