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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Fish83
Frequent Visitor

advanced Moving average of last 10 days

Spoiler
Spoiler
Hi all,

I am trying to calculate the moving average of the last 10 working days. I have data about order processing with columns: order processing date, number of processed orders. given is also a related date table with columns: date, IsWorkingDay, IsHoliday. 
All the dax calculation I tried sofar did not give me the right number. this is because there are working days where there is no processing, and processing is also done occassionally on holidays and weekends. the data is giving in the below table. the 10th of march is a holiday in switzerland and the 8th & 15th of march are weekends. on the 14th of march (friday), there were no processing though working day. 


Thank you in Advance for your help.


DateOrders Volume 
05.03.202521 
06.03.202516 
07.03.20252 
07.03.20251 
08.03.202563 
10.03.202523 
11.03.202570 
12.03.202527 
12.03.20253 
13.03.202534 
15.03.202525 
17.03.20251 
17.03.202520 
18.03.202537 
19.03.20252 


 the date table is below:

Date           Year  M     Month  W     WD   Holiday

05.03.2520253März10TrueFalse
06.03.2520253März10TrueFalse
07.03.2520253März10TrueFalse
08.03.2520253März10FalseTrue
09.03.2520253März10FalseTrue
10.03.2520253März11TrueTrue
11.03.2520253März11TrueFalse
12.03.2520253März11TrueFalse
13.03.2520253März11TrueFalse
14.03.2520253März11TrueFalse
15.03.2520253März11FalseTrue
16.03.2520253März11FalseTrue
17.03.2520253März12TrueFalse
18.03.2520253März12TrueFalse
19.03.2520253März12TrueFalse
5 REPLIES 5
v-veshwara-msft
Community Support
Community Support

Hi @Fish83 ,

Thanks for reaching out to Microsoft Fabric Community.

Just checking in to see if your issue is resolved by now. If not, please consider the following:

To correctly calculate the moving average for the last 10 working days, consider using a fixed anchor date such as a date slicer selection or a separate reference date in your model rather than the latest order processing date, which may have gaps. This approach ensures consistency even when there are missing processing dates in your data.

For identifying working days, make sure your logic includes both IsWorkingDay = True() and IsHoliday = False() conditions together, so holidays are excluded properly when calculating the list of last 10 working days.

 

Hope this helps.

If you have found another solution that works for you, please share it here to help the community.

If any response in this thread was helpful, please mark it as the accepted solution to assist others with similar queries. A kudos would also be appreciated.

Thank you.

sanalytics
Super User
Super User

@Fish83  One request for you..Can you provide your expected output result ,it will help us to write the code for your measure.

 

Thanks

sanalytics

Hi Sanalytics,

Thank you for your help. Sure, the outcome should be about 34.

Fish83
Frequent Visitor

Hi Bhanu,

Thank you for your Solution. Unfortunately it's still not working. first, the IsWorkingDay needs also to consider Holidays (Is Holiday = False). Also, I can not take the VAR current Date from the processing date, as I have missing dates (that are working days, but no processing was done). Also getting the below error:

"The number of arguments is invalid. Function CONTAINSROW must have a value for each column in the table expression"

 

Thank you again

bhanu_gautam
Super User
Super User

@Fish83 Create a calculated column to identify the working days in your order processing table:

IsWorkingDay =
LOOKUPVALUE(
'DateTable'[WD],
'DateTable'[Date],
'OrderProcessing'[Order Processing Date]
)

 

Create a measure to calculate the moving average of the last 10 working days:

Moving Average Last 10 Working Days =
VAR CurrentDate = MAX('OrderProcessing'[Order Processing Date])
VAR Last10WorkingDays =
CALCULATETABLE(
TOPN(
10,
FILTER(
ALL('DateTable'),
'DateTable'[Date] <= CurrentDate && 'DateTable'[WD] = TRUE()
),
'DateTable'[Date],
DESC
)
)
RETURN
AVERAGEX(
FILTER(
'OrderProcessing',
'OrderProcessing'[Order Processing Date] IN Last10WorkingDays
),
'OrderProcessing'[Orders Volume]
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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