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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Kenta
Frequent Visitor

Average 4wk unit sales

Hi,

 

I'm currently trying to modify a formula to show only past 4 weeks of sales. Currently, the formula shows average unit sales for all selected weeks in the dashboard.

 

This is the current formula:

 

Avg. Wk U Sls C2024 =
AVERAGEX(FILTER(ALLSELECTED('Master - Calendar Linear View'[Date].[Date]),
'Master - Calendar Linear View'[Date].[Date] <= MAX('Master - Calendar Linear View'[Date].[Date])),
[Total U C2024])
 
I would like it to always show the last 4 weeks of sales and not an average for all selected weeks.
 
Thanks!
1 ACCEPTED SOLUTION
ToddChitt
Super User
Super User

First: Do you have a contiguous Date dimension attached to your fact table. Let's assume you do.

Create a calculated column in the Date table of [Weeks Back] = DATEDIFF(WEEK, 'Date'[Date], TODAY() )

NOTE: Not sure if the DAX is 100% accurate here, going from memory.

Now create your measure:

Last Four Weeks Sales = CALCULATE ( SUM ( <some column> ), 'Date'[Weeks Back] IN {1, 2, 3, 4} )

 




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





View solution in original post

1 REPLY 1
ToddChitt
Super User
Super User

First: Do you have a contiguous Date dimension attached to your fact table. Let's assume you do.

Create a calculated column in the Date table of [Weeks Back] = DATEDIFF(WEEK, 'Date'[Date], TODAY() )

NOTE: Not sure if the DAX is 100% accurate here, going from memory.

Now create your measure:

Last Four Weeks Sales = CALCULATE ( SUM ( <some column> ), 'Date'[Weeks Back] IN {1, 2, 3, 4} )

 




Did I answer your question? If so, mark my post as a solution. Also consider helping someone else in the forums!

Proud to be a Super User!





Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.