Forum Discussion
Calculate Median
Hi Datafam , I have two columns time to spin and spins. For each time to spin , there are multiple spins . Now i need to calculate median for time to spin. can someone please help me with the appropriate DAX formula to get the result.
Attaching the sample data here.
| Time to spin | Spins |
| 1 | 1 |
| 2 | 7 |
| 3 | 1 |
| 4 | 5 |
| 5 | 5 |
| 6 | 2 |
| 7 | 4 |
| 8 | 1 |
| 9 | 2 |
3 Replies
- mlsx4Memorable Member
Hi AlwaysDeepak
You can do it in DAX:
Median spins = MEDIAN(MyTable[Time to spin])Or in Power Query:
= Table.Group(#"Headers promoted", {"Spins"}, {{"Median", each List.Median([Time to spin]), type number}})- AlwaysDeepakNew Member
we have aggregated our data to number of spins to reduce number of records. This method will again explode my dataset. I already have 45M records. Any formula in DAX would be really helpful. Thanks.
- AnonymousNot applicable
Hi AlwaysDeepak ,
I understand that you have aggregated your data to the number of spins to reduce the number of records. You can use the following DAX formula to calculate the median for the “Time to spin” column without exploding your dataset:
MEDIANX( ADDCOLUMNS( GENERATESERIES(1, MAX('Table'[Spins]), 1), "Time to spin", DIVIDE(MAX('Table'[Time to spin]), MAX('Table'[Spins])) ), [Time to spin] )Replace 'Table' with the name of your table. This formula will return the median value for the “Time to spin” column without exploding your dataset.
I hope this helps!
Reference: Solved: Calculate median of aggregated data - Microsoft Fabric Community
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.