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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
YasminYas
Helper I
Helper I

Calculate past 7days Rolling average of 2 columns

Hi All,
I have data like this. I want to calculate past 7 days rolling average and the folrmula should be 

[sum(Pass wafers in past 7D)] / [sum(Pass + Fail wafers in past 7D)]
I have 3 filters in my power bi as Year , Month and Day. Please help me with Dax
My approach was :
1.Calculated pass pass percentage 

Pass Percentage = divide(CALCULATE(count(YIELD[WAFERPASS])),CALCULATE(count(YIELD[QC_DATE_OUT]),ALLSELECTED(YIELD[WAFERPASS])))
2.Calculated 7D pass pass percentage using Quick measures
Pass Percentage 7D rolling average =
if(ISBLANK([QC_Pass Percentage]),BLANK(),
IF(
ISFILTERED('YIELD'[QC_DATE_OUT]),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy or primary date column."),
VAR __LAST_DATE = LASTDATE('YIELD'[QC_DATE_OUT].[Date])
RETURN
AVERAGEX(
DATESBETWEEN(
'YIELD'[QC_DATE_OUT].[Date],
DATEADD(__LAST_DATE, -7, DAY),
__LAST_DATE
),
CALCULATE([QC_Pass Percentage])
)
))
 
Still didn't get the correct figures
 

Thanks In advance


Waf.PNG

1 ACCEPTED SOLUTION

Hi All,

This Dax used for me to calculated 7D_Rolling average:
 7D_Rolling average=

VAR LAST_DATE = LASTDATE('YIELD'[QC_DATE_OUT].[Date])

Var Sum_waferpasses_7 = calculate(sum(YIELD[WAFERPASS]),DATESBETWEEN('YIELD'[QC_DATE_OUT].[Date],DATEADD(LAST_DATE, -6, DAY),LAST_DATE))

    Var Sum_allthewafers_7 = calculate(sum(YIELD[TotalWafers]),DATESBETWEEN('YIELD'[QC_DATE_OUT].[Date],DATEADD(LAST_DATE, -6, DAY),LAST_DATE))

    return divide(Sum_waferpasses_7 ,Sum_allthewafers_7))

Thanks

 

View solution in original post

3 REPLIES 3
v-cherch-msft
Employee
Employee

Hi @YasminYas

 

I would suggest you create a rolling sum first.Then divide it with 7.Please refer to this article.

https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/

If you need further help, please share a simplified data sample and expected output.You can upload the .pbix to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

There is a Rolling Average quick measure I believe. Also, See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi All,

This Dax used for me to calculated 7D_Rolling average:
 7D_Rolling average=

VAR LAST_DATE = LASTDATE('YIELD'[QC_DATE_OUT].[Date])

Var Sum_waferpasses_7 = calculate(sum(YIELD[WAFERPASS]),DATESBETWEEN('YIELD'[QC_DATE_OUT].[Date],DATEADD(LAST_DATE, -6, DAY),LAST_DATE))

    Var Sum_allthewafers_7 = calculate(sum(YIELD[TotalWafers]),DATESBETWEEN('YIELD'[QC_DATE_OUT].[Date],DATEADD(LAST_DATE, -6, DAY),LAST_DATE))

    return divide(Sum_waferpasses_7 ,Sum_allthewafers_7))

Thanks

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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