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.
Hi
I have a measure, an SMA (Simple Mobile Average), and I need to calculate the MAX of it.
It should be simple, but I can't find what am I doing wrong.
In my case I have a table (allDataCSV). Each row represents an event, and it has a DATE. I can calculate the num of events that occur in when filtering the table (just count rows):
Count = COUNTROWS()
And my SMA is calculated this way:
How can I get the MAX of [CountSMA5Days], that, in that case, should be 213?
Solved! Go to Solution.
I finally found the solution. Its a small modification to my original measure
MaxSMA = MAXX( all(allDataCSV[Day]), [CountSMA5Days])
I came to this solution thanks to another PowerBI user, who guided me with this comment:
I mean your measure MaxSMA = MAXX(allDataCSV,[CountSMA5Days]) DAX converts to MaxSMA = MAXX(allDataCSV,CALCULATE([CountSMA5Days])). So, all data in rows filters your measure.
Thats why count is ALLWAYS 1 when calculating [CountSMA5Days], and so, MAXX is 1. So, the solution is remove filter only for Dates, so I get all dates, but rest of filters apply and [Count] is calculated well.
https://docs.microsoft.com/en-us/dax/all-function-dax
ALL (Column[, Column[, …]])
Removes all filters from the specified columns in the table; all other filters on other columns in the table still apply. All column arguments must come from the same table. The ALL(Column) variant is useful when you want to remove the context filters for one or more specific columns and to keep all other context filters.
That's it!
I finally found the solution. Its a small modification to my original measure
MaxSMA = MAXX( all(allDataCSV[Day]), [CountSMA5Days])
I came to this solution thanks to another PowerBI user, who guided me with this comment:
I mean your measure MaxSMA = MAXX(allDataCSV,[CountSMA5Days]) DAX converts to MaxSMA = MAXX(allDataCSV,CALCULATE([CountSMA5Days])). So, all data in rows filters your measure.
Thats why count is ALLWAYS 1 when calculating [CountSMA5Days], and so, MAXX is 1. So, the solution is remove filter only for Dates, so I get all dates, but rest of filters apply and [Count] is calculated well.
https://docs.microsoft.com/en-us/dax/all-function-dax
ALL (Column[, Column[, …]])
Removes all filters from the specified columns in the table; all other filters on other columns in the table still apply. All column arguments must come from the same table. The ALL(Column) variant is useful when you want to remove the context filters for one or more specific columns and to keep all other context filters.
That's it!
Try this measure:
MaxSMA =
CALCULATE ( [CountSMA5Days], ALLSELECTED ( allDataCSV ) )
Proud to be a Super User!
Sorry, Nope.
It gives me a value of 73,6, that I think could be the average of all [Count]. The 'ALLSELECTED ( allDataCSV )' removes all context for 'allDataCSV', so the AVERAGEX it does not takes only last five days, but all days.
Thaks for your post, witch helped me for another need I had 🙂
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 |
---|---|
104 | |
104 | |
87 | |
73 | |
66 |
User | Count |
---|---|
122 | |
112 | |
98 | |
79 | |
72 |