Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply

Max value of a SMA (Simple Mobile Average) MEASURE in selected range

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:

 

CountSMA5Days = AVERAGEX(
        DATESINPERIOD(allDataCSV[Day],LASTDATE(allDataCSV[Day]),-5,DAY),
            [Count])
 
I want to calulate the MAX value of [CountSMA5Days]. It is a measure, not a field, so I cant use MAX. I have tried MAXX, with no luck:
 
MaxSMA = MAXX(allDataCSV,[CountSMA5Days])
 
It returns me '1', and I understand it is because it evals row by row, and, in ths case, [CountSMA5Days] returns an average of 5 'ones'
 
MaxofMeasure.jpg

How can I get the MAX of [CountSMA5Days], that, in that case, should be 213?

 

1 ACCEPTED 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!

View solution in original post

3 REPLIES 3

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!

DataInsights
Super User
Super User

@Francisco_G_Cal,

 

Try this measure:

 

MaxSMA =
CALCULATE ( [CountSMA5Days], ALLSELECTED ( allDataCSV ) )




Did I answer your question? Mark my post as a solution!

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 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.