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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
mboucher_rcr
Frequent Visitor

Last 8 Weeks Relative to Slicer End Date

Hi,

I'm sure someone has asked this before but I've trawled through a heap of posts and can't quite find one that works for me.

I have a date slicer with start and end dates, and I have the below measure which gives me the average sales quantity over the last 8 weeks.

 

Qty Avg 8Wks =
VAR previousWeekDate =
TODAY () - WEEKDAY ( TODAY (), 1 )
RETURN
CALCULATE (
SUM ( ItemSales[Qty] ),
FILTER (
ItemSales,
ItemSales[WkStartDate] <= previousWeekDate
&& ItemSales[WkStartDate] >= ( previousWeekDate - 56 )
)
) / 8

 

The measure gives me the last 8 weeks average quantity from today, but I want it to give me the last 8 weeks from the end date of the slicer selection. 

 

Can anyone help please?

 

Thanks,

Michael

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @mboucher_rcr ,

According to your description, as in your formula below, you specify the end date is the closest Saturday before today, not the end date of the slicer selection. 

VAR previousWeekDate =
TODAY () - WEEKDAY ( TODAY (), 1 )

Modify you formula like this:

Qty Avg 8Wks =
VAR SelectedDay =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[Date] )
VAR previousWeekDate =
    SelectedDay - WEEKDAY ( SelectedDay, 1 )
RETURN
    CALCULATE (
        SUM ( ItemSales[Qty] ),
        FILTER (
            ItemSales,
            ItemSales[WkStartDate] <= previousWeekDate
                && ItemSales[WkStartDate] >= ( previousWeekDate - 56 )
        )
    ) / 8

Get the correct result in my sample.

vkalyjmsft_1-1656407704906.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

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

3 REPLIES 3
v-yanjiang-msft
Community Support
Community Support

Hi @mboucher_rcr ,

According to your description, as in your formula below, you specify the end date is the closest Saturday before today, not the end date of the slicer selection. 

VAR previousWeekDate =
TODAY () - WEEKDAY ( TODAY (), 1 )

Modify you formula like this:

Qty Avg 8Wks =
VAR SelectedDay =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[Date] )
VAR previousWeekDate =
    SelectedDay - WEEKDAY ( SelectedDay, 1 )
RETURN
    CALCULATE (
        SUM ( ItemSales[Qty] ),
        FILTER (
            ItemSales,
            ItemSales[WkStartDate] <= previousWeekDate
                && ItemSales[WkStartDate] >= ( previousWeekDate - 56 )
        )
    ) / 8

Get the correct result in my sample.

vkalyjmsft_1-1656407704906.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

Create a Calendar Table with a relationship (Many to One and Single) from the WkStartDate column of the ItemSales table to the Date column of the Calendar Table.  Write this measure:

= CALCULATE(SUM(ItemSales[Qty]),DATESBETWEEN('Calendar'[Date],max('Calendar'[Date])-56,max('Calendar'[Date])))/8

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Please define what you mean by "week" .  Ideally you have a calendar table with week numbers. How do you handle transitions between (fiscal) years ?  Say, "today" is February 1.  What's your definition of "past 8 weeks" in that scenario?

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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