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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
monojchakrab
Resolver III
Resolver III

Add date filter to 7 day moving average formula

Hiya All,

 

I have a 7 day moving average code as shown below :

7 day MA = 

CALCULATE(
    AVERAGEX(SUMMARIZE('Date Table', 'Date Table'[Date]),
          'Measures tray'[Total Sales]),
              DATESINPERIOD('Date Table'[Date],LASTDATE('Date Table'[Date]) ,-7,DAY)
)

But the date table is of course auto-populating to the current date - which is 5th of may. But the fact table currently has data updated only till 29th of Apr.

Is it possible to suitably modify this code, to include a date filter to filter for only date <=29/04/2022?

[I know this can be done thru' the filter on the page but I wanted to solve it thru' the code itself]

Thanks and really appreciate your time

Best

2 ACCEPTED SOLUTIONS
PC2790
Community Champion
Community Champion

Did you try using the date from your Fact table instead of Dates Table?

As in LASTDATE(DatefromFactTable)

View solution in original post

monojchakrab
Resolver III
Resolver III

That works of course - but I wanted to avoid that, since I have generated a date table separately and wanted to work off that, with filters to filter to the dates I want to keep in the visual

View solution in original post

2 REPLIES 2
monojchakrab
Resolver III
Resolver III

That works of course - but I wanted to avoid that, since I have generated a date table separately and wanted to work off that, with filters to filter to the dates I want to keep in the visual

PC2790
Community Champion
Community Champion

Did you try using the date from your Fact table instead of Dates Table?

As in LASTDATE(DatefromFactTable)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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