Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I'm trying to come up with a DAX measure that calculates a rolling median based on time of day (minute by minute). I would so appreciate anyone's help. Below is a sample table with random numbers.
Time | Current Minute Value | Previous Minute Value | Chg Pct | ABS Median Chg Pct |
12:00:00 AM | 0.785711 | |||
12:01:00 AM | 0.26775 | 0.785711 | 65.92% | |
12:02:00 AM | 0.747933 | 0.26775 | 179.34% | |
12:03:00 AM | 0.526295 | 0.747933 | 29.63% | |
12:04:00 AM | 0.78565 | 0.526295 | 49.28% | |
12:05:00 AM | 0.457754 | 0.78565 | 41.74% | |
12:06:00 AM | 0.3022 | 0.457754 | 33.98% | |
12:07:00 AM | 0.591653 | 0.3022 | 95.78% | |
12:08:00 AM | 0.473531 | 0.591653 | 19.96% | |
12:09:00 AM | 0.167056 | 0.473531 | 64.72% | |
12:10:00 AM | 0.165168 | 0.167056 | 1.13% | |
12:11:00 AM | 0.443298 | 0.165168 | 168.39% | |
12:12:00 AM | 0.429817 | 0.443298 | 3.04% | |
12:13:00 AM | 0.754753 | 0.429817 | 75.60% | |
12:14:00 AM | 0.405229 | 0.754753 | 46.31% | |
12:15:00 AM | 0.565165 | 0.405229 | 39.47% | 46.31% |
12:16:00 AM | 0.670337 | 0.565165 | 18.61% | 41.74% |
12:17:00 AM | 0.274024 | 0.670337 | 59.12% | 41.74% |
First of all, I have a "Date" and "Day of Week" column that I purposely haven't added because I want to be able to add a filter visual to change to a different day of the week at will. The time and value (current minute) columns are from the source table. The "previous minute value" is a calculated column that uses an index column with a lookup formula to display the previous minute value in the same row as the current minute value. The "Chg Pct" is a measure that calculates the change in value from one minute to the next, and displays as an absolute number. Here's the DAX measure:
Solved! Go to Solution.
Hi @jsflint ,
Sorry for not seeing your request clearly, this is a calculated column for rolling median.
Rolling Median =
IF (
[Time] >= TIME ( 0, 15, 0 ),
CALCULATE (
MEDIAN ( 'Table'[Chg PctABS] ),
FILTER (
ALL ( 'Table' ),
[Time]
>= EARLIER ( 'Table'[Time] ) - TIME ( 0, 15, 0 )
&& [Time] <= EARLIER ( 'Table'[Time] )
)
)
)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @jsflint ,
I got the Previous Minute Value column and Chg Pct ABS column by creating calculated columns.
First, I add an index column in Power Query.
Then
Previous Minute Value = CALCULATE(SUM('Table'[Current Minute Value]),FILTER('Table',[Index]=EARLIER('Table'[Index])-1))
Chg PctABS = ABS(DIVIDE(([Current Minute Value]-[Previous Minute Value]),[Previous Minute Value]))
The median of Chg Pct ABS, just use the MEDIAN function. Here I created the measure with MEDIAN.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks, @v-stephen-msft . It looks like your way (which is still great) comes to the same result as mine. My goal is to generate a rolling median similar to a rolling average, and in a table and/or chart.
I do appreciate the application of EARLIER, though. I've been trying to understand that particular function, and you've made it clear to me.
Do you know how I could add a column that will calculate a rolling median? Thanks again!
Hi @jsflint ,
Sorry for not seeing your request clearly, this is a calculated column for rolling median.
Rolling Median =
IF (
[Time] >= TIME ( 0, 15, 0 ),
CALCULATE (
MEDIAN ( 'Table'[Chg PctABS] ),
FILTER (
ALL ( 'Table' ),
[Time]
>= EARLIER ( 'Table'[Time] ) - TIME ( 0, 15, 0 )
&& [Time] <= EARLIER ( 'Table'[Time] )
)
)
)
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks!