Supplies are limited. Contact info@espc.tech right away to save your spot before the conference sells out.
Get your discountScore big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount
I am trying to urgently calculate a 7 day moving a average but im having issues. I could do it in Excel but i want to use Power BI to present the data instead and my DAX is a little rusty as i havent used it for 4 years!
I have created a formula as follows:
Solved! Go to Solution.
Hi,
I do not fully understand the DAX formula, but I think it has to have one more ) at the end of the formula.
7 day moving average =
CALCULATE (
SUM ( 'PCR TEsting Data'[Total Volume of Tests (Excl. work in progress or tests referred out) (No.)] ) / 7,
DATESINPERIOD (
'PCR TEsting Data'[Relevant Date],
LASTDATE ( 'PCR TEsting Data'[Relevant Date] ),
-7,
DAY
)
)
Hi @NicoleApple,
It seems like a DAX syntax issue that loses the right brackets at the end of your formula. You can add it to the end to fix this issue.
7 day moving average =
CALCULATE (
SUM ( 'PCR TEsting Data'[Total Volume of Tests (Excl. work in progress or tests referred out) (No.)] ) / 7,
DATESINPERIOD (
'PCR TEsting Data'[Relevant Date],
LASTDATE ( 'PCR TEsting Data'[Relevant Date] ),
-7,
DAY
)
)
If the above expression does not work, you can also try to use the date function to manually calculate the moving average.
7 day moving average =
VAR currDate =
MAX ( 'PCR TEsting Data'[Relevant Date] )
VAR prevDate =
DATE ( YEAR ( currDate ), MONTH ( currDate ), DAY ( currDate ) - 7 )
VAR summary =
SUMMARIZE (
FILTER (
ALLSELECTED ( 'PCR TEsting Data' ),
[Relevant Date] >= prevDate
&& [Relevant Date] <= currDate
),
[Relevant Date],
"Total", SUM ( 'PCR TEsting Data'[Total Volume of Tests] )
)
RETURN
AVERAGEX ( summary, [Total] )
Regards,
Xiaoxin Sheng
Hi,
I do not fully understand the DAX formula, but I think it has to have one more ) at the end of the formula.
7 day moving average =
CALCULATE (
SUM ( 'PCR TEsting Data'[Total Volume of Tests (Excl. work in progress or tests referred out) (No.)] ) / 7,
DATESINPERIOD (
'PCR TEsting Data'[Relevant Date],
LASTDATE ( 'PCR TEsting Data'[Relevant Date] ),
-7,
DAY
)
)
User | Count |
---|---|
14 | |
9 | |
8 | |
7 | |
5 |
User | Count |
---|---|
24 | |
16 | |
15 | |
10 | |
7 |