Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello,
I have data like so:
7 Day Rolling Census =
VAR sumper =
CALCULATE (
SUM ( 'Pace Alert Rollup'[Census] ),
DATESINPERIOD (
'Pace Alert Rollup'[Date],
MIN ( 'Pace Alert Rollup'[Date] ),
-7,
DAY
)
)
VAR daysinperiod =
CALCULATE (
DISTINCTCOUNT ( 'Pace Alert Rollup'[Date] ),
DATESINPERIOD (
'Pace Alert Rollup'[Date],
MAX ( 'Pace Alert Rollup'[Date] ),
-7,
DAY
)
)
RETURN
sumper / daysinperiod
I want the user to be able to select the period which the 7 day rolling average is running. For example:
This table shows with a max date of 1/07 and no min date (starting rolling period from minimum of data in the dataset).
This table filtered out the first couple days of the dataset, but still starts the rolling calculation as if there was no date filter. This table should read something like this:
| Date | Rolling Census | Census |
| 1/03/21 | 2199 | 2199 |
| 1/04/21 | 2246 ((2199+2293)/2) | 2293 |
| 1/05/21 | 2312((2199+2293+2445)/3) | 2445 |
| 1/06/21 | 2349((2199+2293+2445+2459)/4) | 2459 |
| 1/07/21 | 2375((2199+2293+2445+2459+2483)/5) | 2483 |
So essentially Im wondering how to get that DATESINPERIOD function to take the dates set by a filter instead of those in the dataset.
Solved! Go to Solution.
@hwr7dd , I think you have take cumm approch with allselected . assuming date range is selected
Cumm Avg= divide( CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=max(date[date]))) ,
CALCULATE(distinctcount(Date[Month-Year]),filter(allselected(date),date[date] <=max(date[date])), not(isblank(Sales[Sales Amount]))))
or like
Cumm Avg= divide( CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=max(date[date]) && date[date] >=max(date[date])-7)) ,
CALCULATE(distinctcount(Date[Month-Year]),filter(allselected(date),date[date] <=max(date[date]) && date[date] >=max(date[date])-7 ), not(isblank(Sales[Sales Amount]))))
@hwr7dd , I think you have take cumm approch with allselected . assuming date range is selected
Cumm Avg= divide( CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=max(date[date]))) ,
CALCULATE(distinctcount(Date[Month-Year]),filter(allselected(date),date[date] <=max(date[date])), not(isblank(Sales[Sales Amount]))))
or like
Cumm Avg= divide( CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=max(date[date]) && date[date] >=max(date[date])-7)) ,
CALCULATE(distinctcount(Date[Month-Year]),filter(allselected(date),date[date] <=max(date[date]) && date[date] >=max(date[date])-7 ), not(isblank(Sales[Sales Amount]))))
@amitchandak
Sometimes I can't believe how hard you work, and how much you know looking through these forums. Thanks!
Also, quick note for anyone who may find this in the future, I had to change -7 days to -6 days to line up with my correct rolling 7 day avg.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 53 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 74 | |
| 70 | |
| 39 | |
| 35 | |
| 23 |