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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mlmchilli
Frequent Visitor

Filtering data based on last 7 days aggregate

Hello!

 

I'm hoping somebody can help!

 

I have data at a daily level in my fact. I would like to be able to filter months and show all days in that month where the sum of sales in the last 7 days for a month are over £1000. It is important to show each day in a table along with the daily sales value for all qualifying months.

 

The metric below will give me the salesamount for the last 7 days, however, if I use this as a filter (>1000) for my table I only get the days that are over £1000 and not all the days of the month that has total sales of £1000

 

7DaySales =
CALCULATE
(
    SUM (Sales[SalesAmount]),
    FILTER('Calendar','Calendar'[FullDate] >= TODAY()-7)
)
 
Any help is appreciated!
 
Thanks
 
r
1 ACCEPTED SOLUTION

Hi @mlmchilli ,

 

Is this the result you want?

vyadongfmsft_0-1664356392881.png

 

Best regards,

Yadong Fang

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

10 REPLIES 10
mlmchilli
Frequent Visitor

Hello Yadong,

 

Apologies for the delay. I'm going to mark this as the accepted solution as it clearly works.

 

We are still trying to get this into our model as typically the model is a little more complicated than the simplistic example given here but we shall get it sorted.

 

Thanks for your help and guidance!

 

 

mlmchilli
Frequent Visitor

Hello Yadong,

 

We are trying to apply this to our model. Could you please explain what EARLIER does?

 

Thanks  

Hi @mlmchilli ,

 

EARLIER returns the current value of the specified column in an outer evaluation pass of the mentioned column.

 

EARLIER is useful for nested calculations where you want to use a certain value as an input and produce calculations based on that input. In Microsoft Excel, you can do such calculations only within the context of the current row; however, in DAX you can store the value of the input and then make calculation using data from the entire table.

 

EARLIER is mostly used in the context of calculated columns.

 

Please refer to:EARLIER function (DAX) - DAX | Microsoft Learn

 

Best regards,

Yadong Fang

 

v-yadongf-msft
Community Support
Community Support

Hi @mlmchilli ,

 

As you mentioned "I would like to be able to filter months and show all days in that month where the sum of sales in the last 7 days for a month are over £1000", I want to confirm with you ,do you want to filter the most recent month or all months? What is your expected output?

 

Can you share with me some screenshots of your data after hiding sensitive information?

Thanks for your efforts & time in advance.

 

Best regards,

Yadong Fang

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

 

 

 

Hello Yadong

 

Thanks for replying. Below is a simple version of the data. I have tried to simply it so have changed the scenario a little to suit. 

 

We would like to be able to filter the products that have over £1000 aggregate sales amount in the last 7 days of data. The key thing is we show all dates where products have over £1000 in the last 7 days and not just the individual days.

 

In the example below we would filter the grid in PowerBI to show Product 1 with all dates showing. Product 2 would not be shown even though the aggregate is over £1000 the last 7 days is under.

 

Hope this makes sense. Please let me know if anything isnt clear.

 

Thanks!

 

mlmchilli_0-1664267279715.png

 

Hi @mlmchilli ,

 

This is my test table:

vyadongfmsft_0-1664329181371.png

 

First, please create a new table to filter last 7 days:

NewTable = FILTER('Table','Table'[Date]>MAX('Table'[Date])-7 && 'Table'[Date]<=MAX('Table'[Date]))

vyadongfmsft_1-1664329250321.png

 

Calculate sum of salesamount for last 7 days:

Last7days = CALCULATE(SUM('NewTable'[SalesAmount]),FILTER(ALL('NewTable'),'NewTable'[Product] = SELECTEDVALUE('NewTable'[Product])))

vyadongfmsft_2-1664329349056.png

Put the measure just created into Filters:

vyadongfmsft_4-1664329462431.png

Best regards,

Yadong Fang

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

Hi Yadong,

 

Thanks for your reply. Based on your proposed solution we lose all of the days in the month for Product 1. We would like to show all days if the total of the last 7 days is over 1000. Is this possible?

 

Thanks

 

m

Hi @mlmchilli ,

 

I cannot understand  "lose all of the days in the month for Product 1", can you provide more details?

 

Best regards,

Yadong Fang

In the screenshot of your results you only have the last 7 days of data for product 1 so Jan 1,2,3 are missing. We would need to see all days data where the total sales amount in the last 7 days is over £1000. Perhaps this is because you are filtering the fact table down to the last 7 days in your first statement?

 

Hi @mlmchilli ,

 

Is this the result you want?

vyadongfmsft_0-1664356392881.png

 

Best regards,

Yadong Fang

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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