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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Measure evaluates for all dates only when current week is selected on a slicer

Hi,

 

I have a graph that has a column for a variables daily value and a line for the weekly value. The graph plots 6 weeks of data up until the selected week in a slicer (using a calulation group below). Daily data is being added to the data set. When a historical week is selected, this works perfectly as shown here:

cbailey1994_0-1670411126205.png


For some reason, when the current week is selected, the weekly average calculates for all dates to the beginning of the date table. As shown here:

cbailey1994_1-1670411150936.png

 

My weekly average formula is here:

 

 

 

 

weekly average =
VAR currentw =
    MAX ( date_table[WeekOffset] )
VAR enddate =
    CALCULATE ( MAX ( 'Previous Dates'[Date] ), ALLSELECTED ( 'Previous Dates' ) )
VAR startdate =
    CALCULATE ( MIN ( 'Previous Dates'[Date] ), ALLSELECTED ( 'Previous Dates' ) )
VAR period =
    DATESBETWEEN ( date_table[Date], startdate, enddate )
VAR result =
    CALCULATE (
        [Measure],
        FILTER ( ALL ( date_table ), date_table[WeekOffset] = currentw ),
        period
    )
RETURN
    result

 

 

 

 

 

I've used a secondary date table ('previous dates') with a calulation group to show the 6 weeks up until the selected week. The code is below. (This was based on SQL BI's tutorial here: https://www.youtube.com/watch?v=d8Rm7dwM6gc)

 

 

 

 

 

VAR NumDays = -42
VAR endw =
    MAX ( date_table[Date] )
VAR previousdates =
    DATESINPERIOD ( 'Previous Dates'[Date], endw, NumDays, DAY )
VAR result =
    CALCULATE (
        selectedmeasure(),
        REMOVEFILTERS ( date_table ),
        KEEPFILTERS ( previousdates ),
        USERELATIONSHIP ( date_table[Date], 'Previous Dates'[Date] )
    )
RETURN
    result

 

 

 

 

 

To help debug the issue, I created a table and printed the first date and last date of the period variable as well as the result here.
Code: 

FIRSTDATE(period)&"/-/"&LASTDATE(period)&"/-/"&result

 

cbailey1994_2-1670412915227.png

It appears that the period has the correct dates in (6 weeks to the selected week), however it has evaluated the measure for dates over a year ago. This only happens when selecting the current week.

 

Does anyone know why this is happening please?

 

Thanks in advance,

 

Charlie

3 REPLIES 3
Anonymous
Not applicable

@amitchandak - thank you but this is not the bit I have a problem with. My approach is similar to your ranking (I call it offset). However, the bit I am trying to understand is why this evaluates for the whole date table when I have the current week selected (and there is not much data in the current week). This works well when I select any previous weeks.

 

Thanks

Anonymous
Not applicable

Perhaps a clearer way of showing the problem.


I have one measure:

Last 6 weeks Weekly Average = 
VAR NumDays = -42
VAR endw =
    MAX ( date_table[Date] )
VAR previousdates =
    DATESINPERIOD ( 'Previous Dates'[Date], endw, NumDays, DAY )
VAR result =
    CALCULATE (
        [MPS (weekly average)],
        REMOVEFILTERS ( date_table ),
        KEEPFILTERS ( previousdates ),
        USERELATIONSHIP ( date_table[Date], 'Previous Dates'[Date] )
    )
RETURN
    result

This calls the measure:

MPS (weekly average) =
VAR currentw =
    MAX ( date_table[WeekOffset] )
VAR enddate =
    CALCULATE ( MAX ( 'Previous Dates'[Date] ), ALLSELECTED ( 'Previous Dates' ) )
VAR startdate =
    CALCULATE ( MIN ( 'Previous Dates'[Date] ), ALLSELECTED ( 'Previous Dates' ) )
VAR period =
    DATESBETWEEN ( date_table[Date], startdate, enddate )
VAR result =
    CALCULATE (
        [M_MPS (Chapter)],
        FILTER ( ALL ( date_table ), date_table[WeekOffset] = currentw ),
        period
    )
RETURN
    result

 

This works to show me the weekly average of the 6 weeks up until the date selected on the slicer for all slicer selections, except when selecting the current week.

amitchandak
Super User
Super User

@Anonymous , I usually use week rank column

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

you can get 6 week

Last 6 weeks = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-6 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Avg Last 6 weeks = CALCULATE(Averagex(Values('Date'[Week Rank]), [orders ]) , FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-6 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors