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
Anonymous
Not applicable

Get Median values for specific time range after aggregation

Hello everyone,

I am struggling to get a MEDIAN value for a specific time limit (just only for the first 3 or 4 months).

The data set is daily data but I would like to compute the Median value after aggregating by monthly.

Date Users
9/7/2022 29
9/12/2022 21
9/16/2022 20
9/30/2022 28
10/1/2022 24
10/5/2022 15
10/18/2022 13
10/26/2022 30
10/31/2022 24
11/10/2022 15
11/15/2022 24
11/17/2022 12
11/23/2022 23
11/30/2022 27
12/2/2022 26
12/6/2022 20
12/13/2022 14
12/14/2022 17

I have the above table and it would be easy if we get the median value from this dataset.


But what I am trying is that SUM( [Views] ) by monthly and finding MEDIAN, it would be for 3 months or 4 months.

So, monthly views, Median and Median for the first 3 month would be look like below,

 Year Month Total Views Median Median for 3 months

2022

 9 98 99.5 101
2022 10 106 99.5 101
2022 11 101 99.5 101
2022 12 77 99.5 101

 

The presenting would be just like above table or creating a line chart over Year,Month level.

Capture.PNG

Please help me to write the DAX formula to get this MEDIAN value.

Thank you for your help and if the question does not make sense, I will try to rephrase.

Thanks.

1 ACCEPTED SOLUTION

Hi, @Anonymous 

 

You can try the following methods.

Measure:

4month = 
Var _table=SUMMARIZE('Table','Table'[Year],'Table'[Month],"Sum",[Total View])
Return
MEDIANX(_table,[Sum])

vzhangti_0-1671173721498.png

3month = 
Var _table=SUMMARIZE('Table','Table'[Year],'Table'[Month],"Sum",[Total View])
Return
MEDIANX(FILTER(_table,[Month]>=9&&[Month]<=11),[Sum])

vzhangti_1-1671173754722.png

2month = 
Var _table=SUMMARIZE('Table','Table'[Year],'Table'[Month],"Sum",[Total View])
Return
MEDIANX(FILTER(_table,[Month]>=9&&[Month]<=10),[Sum])

vzhangti_2-1671173784814.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.
Measure:

Total Views = CALCULATE(SUM('Table'[Users]),ALLEXCEPT('Table','Table'[Year],'Table'[Month]))
MEDIAN = MEDIANX(ALL('Table'),[Total Views])

vzhangti_0-1671160301399.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you @v-zhangti . Your answer helps me a lot.

 

I am curious why the MEDIAN did not result 99.5?

MEDIAN should be 99.5 and MEDIAN for the first 3 months should be 101.00. Am I right?

 

May I know how can I customize if I want to calculate only just for 2 months, 3 months, etc?

Hi, @Anonymous 

 

You can try the following methods.

Measure:

4month = 
Var _table=SUMMARIZE('Table','Table'[Year],'Table'[Month],"Sum",[Total View])
Return
MEDIANX(_table,[Sum])

vzhangti_0-1671173721498.png

3month = 
Var _table=SUMMARIZE('Table','Table'[Year],'Table'[Month],"Sum",[Total View])
Return
MEDIANX(FILTER(_table,[Month]>=9&&[Month]<=11),[Sum])

vzhangti_1-1671173754722.png

2month = 
Var _table=SUMMARIZE('Table','Table'[Year],'Table'[Month],"Sum",[Total View])
Return
MEDIANX(FILTER(_table,[Month]>=9&&[Month]<=10),[Sum])

vzhangti_2-1671173784814.png

Is this the result you expect?

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thank you very much @v-zhangti .

 

Your solution is very helpful for me.

Best Regards.

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.