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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sgupta22
Helper II
Helper II

Rolling median not same as that in Excel

Hi,

 

I am trying to calculate the rolling median of a measure using the following formula:

 

Median EBIT margin = CALCULATE(MEDIANX('All Measures', [EBIT margin]), FILTER(ALL('Calendar'), 'Calendar'[Date] <= MAX('Calendar'[Date])))
 
However, this formula gives me results which are different from those calculated in MS Excel using the same underlying raw data (from the 3rd row onwards).  Below, I am giving the actual [EBIT margin] values along with the Median values that I get using Power BI and Excel. Would really appreciate if someone can point out what I am doing wrong or point me in the right direction.
 
Thank you very much!
Shashank
 
DateActual EBIT marginMedian using ExcelMedian using Power BI
20105.7%5.7%5.7%
20117.2%6.4%6.4%
201211.7%7.2%8.2%
20138.6%7.9%8.3%
201413.7%8.6%9.5%
20159.7%9.1%9.6%
201610.8%9.7%9.8%
201715.7%10.3%10.8%
201814.5%10.8%11.3%

 

@Ashish_Mathur 

2 ACCEPTED SOLUTIONS

Hi,

You may download my PBI file from here.  Reapply the conditions in the slicers.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

You are welcome.  Thank you for your kind words.  Please download the revised file from here.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks for your reply Ashish.

 

Strangely, it's not working in my file (getting blank) even though I can see you are getting the right values.  There must be something wrong in my file.  I am attaching it here if that helps.

 

Thank you very much for your help.  Much appreicated. 

 

Regards

Shashank

Hi,

You may download my PBI file from here.  Reapply the conditions in the slicers.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This works! Thanks a ton!! You are a genius.

 

Just one more question if I can indulge you.  Is there a way the start date can be dynamic?  For example, it should start with the minimum date at which the [EBIT margin] is not "blank" or "0"?

 

Thanks a ton again.

 

Cheers

Shashank  

You are welcome.  Thank you for your kind words.  Please download the revised file from here.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This is amazing 😊  Thank you again so much!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
johnt75
Super User
Super User

You're not doing the iteration over the years, try

Median EBIT =
CALCULATE (
    MEDIANX ( VALUES ( 'Calendar'[Year] ), [EBIT] ),
    REMOVEFILTERS ( 'Calendar' ),
    'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
)

Thank you johnt75 for your reply.

 

Unfortunately, when I use the above formula, I don't get any values for the Median EBIT.  It just becomes blank.

Hmm, it worked for me. 

Are you using the Calendar[Year] column in the table visual? What is the defintion of the [EBIT] measure ?

Yes, I am... Actually the measure is EBIT margin and it's formula is below:

 

 

 

EBIT margin =
    VAR Revenue = SUM(Data[Total Revenue])
    VAR EBIT = [Adjusted EBIT]
RETURN
    IF(Revenue = 0, BLANK(), EBIT / Revenue)

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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