Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more.
Get startedGrow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.
Dear Community,
I am trying to calculate the 13 Week Moving Average.
My data model is very simple.
Please see below for my current attempt and error message.
Greatly appreciate any and all help with this issue.
Thank you in advance!
Solved! Go to Solution.
Here is your code...
90 Day Average =
VAR sDate = MAX('Table2'[Date])
VAR bDate = sDate-90
VAR sValue = CALCULATE(AVERAGE('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate))
RETURN sValue
Change the "Calculate(Average" to a Max or Min for the other two measures and get the MAX Date.
90 Min =
VAR sDate = MAXX(ALL('Table2'[Date]),'Table2'[Date])
VAR bDate = sDate-90
VAR sValue = CALCULATE(MIN('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate))
RETURN sValue
Please see below for sample data:
Date Proposals
1/3/2021 | 56 |
1/10/2021 | 101 |
1/17/2021 | 97 |
1/24/2021 | 145 |
1/31/2021 | 205 |
2/7/2021 | 125 |
2/14/2021 | 123 |
2/21/2021 | 143 |
2/28/2021 | 156 |
3/7/2021 | 127 |
3/14/2021 | 141 |
3/21/2021 | 132 |
3/28/2021 | 135 |
4/4/2021 | 162 |
4/11/2021 | 175 |
4/18/2021 | 167 |
4/25/2021 | 209 |
5/2/2021 | 182 |
5/9/2021 | 205 |
5/16/2021 | 154 |
5/23/2021 | 218 |
5/30/2021 | 158 |
6/6/2021 | 248 |
6/13/2021 | 140 |
6/20/2021 | 145 |
6/27/2021 | 112 |
7/4/2021 | 107 |
7/11/2021 | 168 |
7/18/2021 | 156 |
7/25/2021 | 146 |
8/1/2021 | 163 |
8/8/2021 | 161 |
8/15/2021 | 163 |
8/22/2021 | 196 |
8/29/2021 | 193 |
9/5/2021 | 156 |
9/12/2021 | 217 |
9/19/2021 | 262 |
9/26/2021 | 243 |
10/3/2021 | 217 |
10/10/2021 | 232 |
10/17/2021 | 267 |
10/24/2021 | 246 |
10/31/2021 | 191 |
11/7/2021 | 332 |
11/14/2021 | 262 |
11/21/2021 | 70 |
11/28/2021 | 197 |
12/5/2021 | 87 |
12/12/2021 | 73 |
12/19/2021 | 21 |
12/26/2021 | 7 |
1/2/2022 | 111 |
1/9/2022 | 219 |
1/16/2022 | 219 |
1/23/2022 | 210 |
1/30/2022 | 293 |
2/6/2022 | 261 |
2/13/2022 | 212 |
2/20/2022 | 148 |
2/27/2022 | 203 |
3/6/2022 | 225 |
3/13/2022 | 201 |
3/20/2022 | 184 |
3/27/2022 | 199 |
4/3/2022 | 155 |
4/10/2022 | 200 |
4/17/2022 | 235 |
4/24/2022 | 213 |
5/1/2022 | 286 |
5/8/2022 | 135 |
5/15/2022 | 198 |
5/22/2022 | 106 |
5/29/2022 | 134 |
6/5/2022 | 170 |
6/12/2022 | 221 |
6/19/2022 | 163 |
6/26/2022 | 121 |
7/3/2022 | 124 |
7/10/2022 | 149 |
7/17/2022 | 164 |
7/24/2022 | 136 |
7/31/2022 | 213 |
8/7/2022 | 209 |
8/14/2022 | 186 |
8/21/2022 | 208 |
8/28/2022 | 173 |
9/4/2022 | 141 |
9/11/2022 | 221 |
9/18/2022 | 266 |
9/25/2022 | 216 |
10/2/2022 | 279 |
10/9/2022 | 243 |
10/16/2022 | 240 |
10/23/2022 | 216 |
10/30/2022 | 230 |
11/6/2022 | 238 |
11/13/2022 | 287 |
11/20/2022 | 55 |
11/27/2022 | 285 |
12/4/2022 | 290 |
12/11/2022 | 141 |
12/18/2022 | 31 |
12/25/2022 | 12 |
1/2/2023 | 75 |
1/9/2023 | 116 |
1/16/2023 | 167 |
1/23/2023 | 196 |
1/30/2023 | 208 |
2/6/2023 | 183 |
2/13/2023 | 271 |
2/20/2023 | 196 |
2/27/2023 | 195 |
Does this link work for you to get to the Power BI file?
Would something like this help?
My RA =
VAR _Curr = SELECTEDVALUE( 'Proposals'[Index] )
VAR _Result =
AVERAGEX(
FILTER(
ALL( 'Proposals' ),
'Proposals'[Index] <= _Curr
&& 'Proposals'[Index] >= _Curr - 12
),
'Proposals'[Proposals]
)
RETURN
_Result
Hello @grantsamborn
Thank you for your help!
This has helped, but I am still having issues with the formula trying to work on each individual date instead of the once a week. (1/3/21, 1/10/21, 1/17/21...)
I am trying to recreate this excel file, I hope this helps.
Date Presented 90 Day Rolling Average Max Min
Count of Proposal: Proposal Name
1/3/2021 56
1/10/2021 101
1/17/2021 97
1/24/2021 145
1/31/2021 205
2/7/2021 125
2/14/2021 123
2/21/2021 143
2/28/2021 156
3/7/2021 127
3/14/2021 141
3/21/2021 132
3/28/2021 135
4/4/2021 162
4/11/2021 175
4/18/2021 167
4/25/2021 209
5/2/2021 182
5/9/2021 205
5/16/2021 154
5/23/2021 218
5/30/2021 158
6/6/2021 248
6/13/2021 140 175.85 235.85 156.15
6/20/2021 145 175.77 235.85 156.15
6/27/2021 112 176.77 235.85 156.15
7/4/2021 107 175.00 235.85 156.15
7/11/2021 168 170.77 235.85 156.15
7/18/2021 156 170.23 235.85 156.15
7/25/2021 146 169.38 235.85 156.15
8/1/2021 163 164.54 235.85 156.15
8/8/2021 161 163.08 235.85 156.15
8/15/2021 163 159.69 235.85 156.15
8/22/2021 196 160.38 235.85 156.15
8/29/2021 193 158.69 235.85 156.15
9/5/2021 156 161.38 235.85 156.15
9/12/2021 217 154.31 235.85 156.15
9/19/2021 262 160.23 235.85 156.15
9/26/2021 243 169.23 235.85 156.15
10/3/2021 217 179.31 235.85 156.15
10/10/2021 232 187.77 235.85 156.15
10/17/2021 267 192.69 235.85 156.15
10/24/2021 246 201.23 235.85 156.15
10/31/2021 191 208.92 235.85 156.15
11/7/2021 332 211.08 235.85 156.15
11/14/2021 262 224.23 235.85 156.15
11/21/2021 70 231.85 235.85 156.15
11/28/2021 197 222.15 235.85 156.15
12/5/2021 87 222.46 235.85 156.15
12/12/2021 73 217.15 235.85 156.15
12/19/2021 21 206.08 235.85 156.15
12/26/2021 7 187.54 235.85 156.15
1/2/2022 111 169.38 235.85 156.15
1/9/2022 219 161.23 235.85 156.15
1/16/2022 219 160.23 235.85 156.15
1/23/2022 210 156.54 235.85 156.15
1/30/2022 293 153.77 235.85 156.15
2/6/2022 261 161.62 235.85 156.15
2/13/2022 212 156.15 235.85 156.15
2/20/2022 148 152.31 235.85 156.15
2/27/2022 203 158.31 235.85 156.15
3/6/2022 225 158.77 235.85 156.15
3/13/2022 201 169.38 235.85 156.15
3/20/2022 184 179.23 235.85 156.15
3/27/2022 199 191.77 235.85 156.15
4/3/2022 155 206.54 235.85 156.15
4/10/2022 200 209.92 235.85 156.15
4/17/2022 235 208.46 235.85 156.15
4/24/2022 213 209.69 235.85 156.15
5/1/2022 286 209.92 235.85 156.15
5/8/2022 135 209.38 235.85 156.15
5/15/2022 198 199.69 235.85 156.15
5/22/2022 106 198.62 235.85 156.15
5/29/2022 134 195.38 235.85 156.15
6/5/2022 170 190.08 235.85 156.15
6/12/2022 221 185.85 235.85 156.15
6/19/2022 163 187.38 235.85 156.15
6/26/2022 121 185.77 235.85 156.15
7/3/2022 124 179.77 235.85 156.15
7/10/2022 149 177.38 235.85 156.15
7/17/2022 164 173.46 235.85 156.15
7/24/2022 136 168.00 235.85 156.15
7/31/2022 213 162.08 235.85 156.15
8/7/2022 209 156.46 235.85 156.15
8/14/2022 186 162.15 235.85 156.15
8/21/2022 208 161.23 235.85 156.15
8/28/2022 173 169.08 235.85 156.15
9/4/2022 141 172.08 235.85 156.15
9/11/2022 221 169.85 235.85 156.15
9/18/2022 266 169.85 235.85 156.15
9/25/2022 216 177.77 235.85 156.15
10/2/2022 279 185.08 235.85 156.15
10/9/2022 243 197.00 235.85 156.15
10/16/2022 240 204.23 235.85 156.15
10/23/2022 216 210.08 235.85 156.15
10/30/2022 230 216.23 235.85 156.15
11/6/2022 238 217.54 235.85 156.15
11/13/2022 287 219.77 235.85 156.15
11/20/2022 55 227.54 235.85 156.15
11/27/2022 285 215.77 235.85 156.15
12/4/2022 290 224.38 235.85 156.15
12/11/2022 141 235.85 235.85 156.15
12/18/2022 31 211.62 235.85 156.15
12/25/2022 12 195.92 235.85 156.15
1/2/2023 75 180.23 235.85 156.15
1/9/2023 116 170.46 235.85 156.15
1/16/2023 167 164.85 235.85 156.15
1/23/2023 196 163.31 235.85 156.15
1/30/2023 208 161.62 235.85 156.15
2/6/2023 183 157.38 235.85 156.15
2/13/2023 271 156.15 235.85 156.15
2/20/2023 196 167.00 235.85 156.15
2/27/2023 195 160.08 235.85 156.15
Thank you again for your help! Have a great day!
Here is your code...
90 Day Average =
VAR sDate = MAX('Table2'[Date])
VAR bDate = sDate-90
VAR sValue = CALCULATE(AVERAGE('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate))
RETURN sValue
Change the "Calculate(Average" to a Max or Min for the other two measures and get the MAX Date.
90 Min =
VAR sDate = MAXX(ALL('Table2'[Date]),'Table2'[Date])
VAR bDate = sDate-90
VAR sValue = CALCULATE(MIN('Table2'[Count]),FILTER(ALL('Table2'[Date]),'Table2'[Date] >= bDate && 'Table2'[Date] <= sDate))
RETURN sValue
Thank you!
Would you mind posting your power bi file or picture of your data model for me to replicate. I am having issues getting it to work on my end?
I didn't use a data model, just made a copy of your posted data.
The measures are posted in previous. If you have a date table with a relationship then switch out the date fields in the measure with the date fields of the date table.
Also, check your data types, i.e. Date fields are of data type Date. Numbers are of data type Whole or Decimal, etc.
Change MyIndex to
VAR MyIndex = SELECTEDVALUE('Proposals'[Index],<A Default Value>)
A default value can be something like MAX()
MAX('Proposals'[Index])
Change your filter to
FILTER(ALL('Proposals')....
Thank you so much for your quick response.
I have updated the code to the following:
Moving Average =
VAR MyIndex = SELECTEDVALUE('Proposals'[Index],MAX('Proposals'[Index]))
VAR myResult =
AVERAGEX(
FILTER(ALL( 'Proposals'),
'Proposals'[Index] > MyIndex-13 &&
'Proposals'[Index] <= MyIndex
),'Proposals'[Proposals]
)
RETURN FIXED(myResult,2)
Unfortunately, the moving average column is all coming back as "0.00"
Is there an easy way to share my Power BI file?
You have to upload to GIT or Onedrive and share Publicly the link. You could also past sample data and image of the dataset.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Ask questions in Eventhouse and KQL, Eventstream, and Reflex.
User | Count |
---|---|
85 | |
82 | |
64 | |
62 | |
56 |
User | Count |
---|---|
171 | |
112 | |
110 | |
72 | |
72 |