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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply

Filters

Hi all

 

I hope someone can help me.

 

I am calculating an average of a column, and need it to calculate the average for 28 days prior to the MAX value in another column.

When writing my DAX i am unable to overcome the MAX value adhering to the filter context, when I would like it to ignore it.

 

So as an example.

DATE(uk)       ITEM        NUMBER

21/4/22         W            10

12/1/22         E             10
14/11/21       W            20
7/5/22           S             10

The MAX value is '7/5/22' but when the filter context is changed to select 'W' in a slicer, it defaults to '21/4/22', which then throws out the 28 day calculation

Im working with this so far:
CALCULATE(AVERAGE(NUMBER),DATESINPERIOD(DATE,MAX(DATE),-28,DAY))

which works fine, aside from the issue above.

Can anyone assist?

Many thanks




1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @powerbiuser9999 

The reason for this problem is that slicer is using ITEM from the fact table, you need to create another table containing ITEM and use it for slicer.

vxiaotang_1-1654248674221.png

I mean, when you select W from the table below, then it will filter the table where ITEM=W and then return the max date where  ITEM=W. 

vxiaotang_0-1654248536473.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

2 REPLIES 2
v-xiaotang
Community Support
Community Support

Hi @powerbiuser9999 

The reason for this problem is that slicer is using ITEM from the fact table, you need to create another table containing ITEM and use it for slicer.

vxiaotang_1-1654248674221.png

I mean, when you select W from the table below, then it will filter the table where ITEM=W and then return the max date where  ITEM=W. 

vxiaotang_0-1654248536473.png

 

Best Regards,

Community Support Team _Tang

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

AlexisOlson
Super User
Super User

Try calculating the max date as a variable where you use ALL to remove the item filter context from your slicer.

 

For example, your measure might look something like this:

28 Day Avg =
VAR _MaxDate = CALCULATE ( MAX ( Dates[Date] ), ALL ( Table1 ) )
RETURN
    CALCULATE (
        AVERAGE ( Table1[Number] ),
        DATESINPERIOD ( Dates[Date], _MaxDate, -28, DAY )
    )

I don't know what tables and relationships you have though, so you'll need to modify this according to your specific situation.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors