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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Calculate averages by day of the week

I need to create a bar chart with average Sales by Product based on the filter I choose by each day of the week.

 

For example.. if I select Monday in the Dates tables filter, the chart should show the averages of app counts submitted on only Mondays of that month/year/ time period selected in time slicer and similarly for other days of the week.

 

I would really appreciate if someone can help.

2 ACCEPTED SOLUTIONS
v-danhe-msft
Employee
Employee

Hi @Anonymous,

Based on my test, you can refer to below steps:

1.I have entered some sample data to test for your problem. Now you can create a calculated column to calculate the weekday.

weekday = WEEKDAY([Date],1)

2.1.PNG

2.Create a Clustered column chart value and add the [Year], [Month], [Day], and [Value] fields and modify the [Value] field from "Sum" to "Average".

2.2.PNG

Capture.PNG

3.Create a Slicer visual and add the [weekday] field.

2.7.PNG

Now you can filter your data manually.

2.8.PNG

You can also download the PBIX file to have a view. If it doesn’t meet your requirements, please provide some dummy data and clarify the requirement.

https://www.dropbox.com/s/90z48xgpmb5hz12/Calculate%20averages%20by%20day%20of%20the%20week.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
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

Hi @Anonymous,

Based on my previous test pbix file, you can refer to below steps:

1.Create a new measure to calculate the moving average of last 30 days.

Apps 30D Moving Average = CALCULATE(AVERAGE(Table1[Value]),DATESINPERIOD(Table1[Date],LASTDATE(Table1[Date]),-30,DAY))

new 1.PNG

2.Create a Clustered column chart and add the [Date] and [Apps 30D Moving Average] field.

new 2.PNG

3.Use the “weekday slicer” , you can filter last 30 Mondays/Tuesdays data.

new3.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/2j2lwomfij0x9re/Calculate%20averages%20by%20day%20of%20the%20week2.pbix?dl=0

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
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

4 REPLIES 4
v-danhe-msft
Employee
Employee

Hi @Anonymous,

Based on my test, you can refer to below steps:

1.I have entered some sample data to test for your problem. Now you can create a calculated column to calculate the weekday.

weekday = WEEKDAY([Date],1)

2.1.PNG

2.Create a Clustered column chart value and add the [Year], [Month], [Day], and [Value] fields and modify the [Value] field from "Sum" to "Average".

2.2.PNG

Capture.PNG

3.Create a Slicer visual and add the [weekday] field.

2.7.PNG

Now you can filter your data manually.

2.8.PNG

You can also download the PBIX file to have a view. If it doesn’t meet your requirements, please provide some dummy data and clarify the requirement.

https://www.dropbox.com/s/90z48xgpmb5hz12/Calculate%20averages%20by%20day%20of%20the%20week.pbix?dl=0

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-danhe-msft Thank you for sharing the solution. This was really helpful.

 

Now with this bar chart, I also need to include another bar of Moving Average of last 'n' number of Mondays/Tuesdays based on the Weekday selected in the filter. Basically, I have to compare the Avg number of Sales with the Moving Average of Sales by that day for a time frame.

 

Below is the DAX formula I use to calculate the Moving Average of last 30 days:

 

Apps 30D Moving Average= AVERAGEX(
DATESINPERIOD(
Dates[DateKey],
LASTDATE(Dates[DateKey]),
-30,DAY),
[Apps])

 

But, how to implement it for last 30 Mondays/Tuesdays etc. based on the Weekday slicers selected ? I would really appreciate if we could resolve this.

Hi @Anonymous,

Based on my previous test pbix file, you can refer to below steps:

1.Create a new measure to calculate the moving average of last 30 days.

Apps 30D Moving Average = CALCULATE(AVERAGE(Table1[Value]),DATESINPERIOD(Table1[Date],LASTDATE(Table1[Date]),-30,DAY))

new 1.PNG

2.Create a Clustered column chart and add the [Date] and [Apps 30D Moving Average] field.

new 2.PNG

3.Use the “weekday slicer” , you can filter last 30 Mondays/Tuesdays data.

new3.PNG

You can also download the PBIX file to have a view.

https://www.dropbox.com/s/2j2lwomfij0x9re/Calculate%20averages%20by%20day%20of%20the%20week2.pbix?dl=0

 

Regards,

Daniel He

 

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-danhe-msft 

This is great!!

Thank you so much for your quick response. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.