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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
scorbin-j
Helper I
Helper I

How do I calculate the median of the output of a measure?

I am trying to find the median of the weekly issued amount for materials. My first issue was needing to fill in the gaps of weeks without any issuing data and create new rows with 0 when there wasn't a row previously. I believe I have done that with this measure: 

 

QuantityMissingDates = 
    SUMX(
        SUMMARIZE(
            AverageDailyUsage,
            dimTime[ISO_WEEK],
            BRIDGEMM[Materialfull],
            AverageDailyUsage[WeekSUM]
        ),
        [WeekSUM]
    ) + 0

 

Just looking at one material that gets me this table visual:

WeekMaterial IDQty
2024 241017983224
2024 161017983192
2024 081017983128
2024 181017983128
2024 05101798396
2024 19101798396
2024 26101798396
2024 13101798364
2024 15101798364
2024 04101798332
2024 20101798332
2024 0310179830
2024 0610179830
2024 0710179830
2024 0910179830
2024 1010179830
2024 1110179830
2024 1210179830
2024 1410179830
2024 1710179830
2024 2110179830
2024 2210179830
2024 2310179830
2024 2510179830
2024 2710179830
2024 2810179830
2024 2910179830

So those 0 quantities are all "fake" numbers since there wasn't any original data there for those particular weeks. My question is how do I find the median of that new measure that includes the 0s and is dynamic to a date filter and material id filter? 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @scorbin-j ,

 

According to your statement, I think your data model should look like as below.

vrzhoumsft_0-1721628004661.png

I suggest you to try code as below to create a measure.

median = 
VAR _GENERATE = ADDCOLUMNS(GENERATE(VALUES(DimTime[ISO_WEEK]),VALUES(BRIDGEMM[Materialfull])),"Qty",[QuantityMissingDates])
RETURN
MEDIANX(FILTER(_GENERATE,[Materialfull] = MAX(BRIDGEMM[Materialfull])),[Qty])

Result is as below.

vrzhoumsft_1-1721628029491.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Anonymous
Not applicable

Hi @scorbin-j ,

 

According to your statement, I think your data model should look like as below.

vrzhoumsft_0-1721628004661.png

I suggest you to try code as below to create a measure.

median = 
VAR _GENERATE = ADDCOLUMNS(GENERATE(VALUES(DimTime[ISO_WEEK]),VALUES(BRIDGEMM[Materialfull])),"Qty",[QuantityMissingDates])
RETURN
MEDIANX(FILTER(_GENERATE,[Materialfull] = MAX(BRIDGEMM[Materialfull])),[Qty])

Result is as below.

vrzhoumsft_1-1721628029491.png

 

Best Regards,
Rico Zhou

 

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

 

This seems to work, but I also found this method as well:

Median = 
var _table = ADDCOLUMNS((Summarize(allselected(dimTime),dimTime[ISO_WEEK])), "_qtywithzeros",[QuantityMissingDates]) Return MEDIANX(_table, [_qtywithzeros])
rajendraongole1
Super User
Super User

Hi @scorbin-j - calculate the medianmeasure of the weekly issued amount for materials as below 

 

MedianWeeklyQuantity =
CALCULATE(
MEDIANX(
ADDCOLUMNS(
SUMMARIZE(
dimTime,
dimTime[ISO_WEEK],
BRIDGEMM[Materialfull]
),
"WeekSUM",
COALESCE([WeekSUM], 0)
),
[WeekSUM]
)
)

 

Hope it works

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

 





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

Proud to be a Super User!





Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.