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.
Hello community
I'm looking to see if someone can help me as I'm trying to get a Moving average of 5 days and it seems to work the formula but once that I don't select a unique practice the moving average is way off, I usually see around 600-700 visits every day and my moving average if I don't select one location is way off
fist photo is location and second is one location only
thank you and hope to get an answer
Hi @edavilaamerivet,
Please refer to the attached pbix file.
Here is the DAX measure for your reference.
Moving_Average_5_Days =
VAR result =
CALCULATE (
AVERAGEX (
SUMMARIZE ( 'Table', 'Table'[Date], "visit", SUM ( 'Table'[Visits] ) ),
[visit]
),
DATESINPERIOD ( 'Table'[Date], LASTDATE ( 'Table'[Date] ), -5, DAY )
)
RETURN
result
Please let me know your comments.
Regards,
Nandu Krishna
Nandukrishnavs
thanks for trying to help me and I was able to make your formula work and it now works as a group but now the issue is that the average is not working correctly as I need to exclude the Saturdays and Sundays and if I filter them they still be calculated
this is what I'm using
Thanks
Hi @edavilaamerivet,
Create a calculated column in the table Fact_ClientPatientActivity
Weekend =
VAR dayVal =
WEEKDAY ( Fact_ClientPatientActivity[Date] )
VAR result =
IF ( dayVal = 1 || dayVal = 7, TRUE (), FALSE () )
RETURN
result
Then create DAX measure
Moving_Average_5_days2 =
VAR selectedweekday =
CALCULATE ( WEEKDAY ( SELECTEDVALUE ( Fact_ClientPatientActivity[Date] ) ) )
VAR mvgDay =
SWITCH ( selectedweekday, 1, 7, 2, 7, 3, 7, 4, 7, 5, 7, 6, 5, 7, 7 )
VAR result =
CALCULATE (
AVERAGEX (
SUMMARIZE (
FILTER (
Fact_ClientPatientActivity,
Fact_ClientPatientActivity[Weekend] = FALSE ()
),
FACT_ClientPatientActivity[Date],
"# Visits", SUM ( FACT_ClientPatientActivity[PatientVisitCount] )
),
[# Visits]
),
DATESINPERIOD (
FACT_ClientPatientActivity[Date],
LASTDATE ( FACT_ClientPatientActivity[Date] ),
( -1 * mvgDay ),
DAY
)
)
RETURN
result
Now you can apply a visual level/page level filter to exclude Saturday and Sunday.
you might consider creating pbix file that will contain some sample data (remove the confidential info), upload the pbix to onedrive or dropbox and share the link to the file. Please do not forget to describe the expected results based on this sample data.
https://www.dropbox.com/s/xo2qhmqdsi2mznh/Moving%20Average-2.pbix?dl=0
I can't seem to make the formula to work, I have attached a sample of the file with same columns names
Moving_Average_5_days2 =
VAR result =
CALCULATE (
AVERAGEX (
SUMMARIZE(DIM_Date, DIM_Date[Date], "Client Visit", SUM(FACT_ClientPatientActivity[ClientVisitCount] ) ),
[Client Visit]
),
DATESINPERIOD(DIM_Date[Date], LASTDATE(DIM_Date[Date]), -5,DAY)
)
return
result
the dim_date is my Calendar table
"Client visits" this is a calculated column from the sum(clientvisitcount)
Fact_clientpatientactivity is the table were the data for the visits are
also to point out is the State or location is in the Dim_installation table column State'
What I'm thinking the problem is that I'm trying to group the by state "AK" and formula is not at that level
not sure
Thanks
Hi @edavilaamerivet,
Sample Table
Date | Location | Visits |
01-01-2020 | Trivandrum | 200 |
02-01-2020 | Trivandrum | 160 |
03-01-2020 | Trivandrum | 202 |
04-01-2020 | Trivandrum | 230 |
05-01-2020 | Trivandrum | 204 |
06-01-2020 | Trivandrum | 204 |
07-01-2020 | Trivandrum | 130 |
08-01-2020 | Trivandrum | 131 |
09-01-2020 | Trivandrum | 132 |
10-01-2020 | Trivandrum | 133 |
11-01-2020 | Trivandrum | 210 |
12-01-2020 | Trivandrum | 211 |
13-01-2020 | Trivandrum | 212 |
14-01-2020 | Trivandrum | 213 |
15-01-2020 | Trivandrum | 214 |
16-01-2020 | Trivandrum | 215 |
17-01-2020 | Trivandrum | 216 |
18-01-2020 | Trivandrum | 217 |
19-01-2020 | Trivandrum | 218 |
20-01-2020 | Trivandrum | 219 |
21-01-2020 | Trivandrum | 220 |
22-01-2020 | Trivandrum | 221 |
23-01-2020 | Trivandrum | 222 |
24-01-2020 | Trivandrum | 223 |
25-01-2020 | Trivandrum | 224 |
26-01-2020 | Trivandrum | 225 |
27-01-2020 | Trivandrum | 226 |
28-01-2020 | Trivandrum | 227 |
29-01-2020 | Trivandrum | 228 |
30-01-2020 | Trivandrum | 229 |
01-01-2020 | Kochi | 100 |
02-01-2020 | Kochi | 110 |
03-01-2020 | Kochi | 120 |
04-01-2020 | Kochi | 130 |
05-01-2020 | Kochi | 140 |
06-01-2020 | Kochi | 150 |
07-01-2020 | Kochi | 160 |
08-01-2020 | Kochi | 170 |
09-01-2020 | Kochi | 180 |
10-01-2020 | Kochi | 190 |
11-01-2020 | Kochi | 210 |
12-01-2020 | Kochi | 200 |
13-01-2020 | Kochi | 190 |
14-01-2020 | Kochi | 180 |
15-01-2020 | Kochi | 170 |
16-01-2020 | Kochi | 160 |
17-01-2020 | Kochi | 150 |
18-01-2020 | Kochi | 250 |
19-01-2020 | Kochi | 255 |
20-01-2020 | Kochi | 260 |
21-01-2020 | Kochi | 265 |
22-01-2020 | Kochi | 270 |
23-01-2020 | Kochi | 260 |
24-01-2020 | Kochi | 250 |
25-01-2020 | Kochi | 240 |
26-01-2020 | Kochi | 230 |
27-01-2020 | Kochi | 220 |
28-01-2020 | Kochi | 210 |
29-01-2020 | Kochi | 200 |
30-01-2020 | Kochi | 190 |
Please try the below DAX measure
Moving_Average_5_Days =
VAR result =
CALCULATE (
AVERAGEX (
SUMMARIZE ( 'Table', 'Table'[Date], "visit", SUM ( 'Table'[Visits] ) ),
[visit]
),
DATESINPERIOD ( 'Table'[Date], LASTDATE ( 'Table'[Date] ), -5, DAY )
)
RETURN
result
Please let me know if you are finding any issues.
Regards,
Nandu Krishna
https://www.dropbox.com/s/xo2qhmqdsi2mznh/Moving%20Average-2.pbix?dl=0
I can't seem to make the formula to work, I have attached a sample of the file with same columns names
Moving_Average_5_days2 =
VAR result =
CALCULATE (
AVERAGEX (
SUMMARIZE(DIM_Date, DIM_Date[Date], "Client Visit", SUM(FACT_ClientPatientActivity[ClientVisitCount] ) ),
[Client Visit]
),
DATESINPERIOD(DIM_Date[Date], LASTDATE(DIM_Date[Date]), -5,DAY)
)
return
result
the dim_date is my Calendar table
"Client visits" this is a calculated column from the sum(clientvisitcount)
Fact_clientpatientactivity is the table were the data for the visits are
also to point out is the State or location is in the Dim_installation table column State'
What I'm thinking the problem is that I'm trying to group the by state "AK" and formula is not at that level
not sure
Thanks
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
97 | |
75 | |
63 | |
62 |
User | Count |
---|---|
137 | |
105 | |
104 | |
80 | |
63 |