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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Kpham
Resolver I
Resolver I

Median AND sum by

Dear all,

I would like to create a measure that's shows the median of the cost per year by product. Underneath a screenshot of my PBIX. In my original PBIX it don't have the SUM and column 6 column

Kpham_0-1601580091438.png

I got my wrong result with the following DAX. It misses the first step to sum the cost by project.

~ Median 2018 (€) = CALCULATE(MEDIAN(Sheet1[Cost €]),YEAR(Sheet1[Year]=2018))

 pbix --> https://we.tl/t-nxcAYxsZZa

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Kpham 

 

Based on your description, you may create a calculated column and two measures as below. The pbix file is attached in the end.

Calculated column:

 

Y = YEAR([Year])

 

 

Measure:

 

median 2018 = 
var tab = 
SUMMARIZE(
    Sheet1,
    Sheet1[Product],
    Sheet1[Project],
    Sheet1[Y],
    "Re",
    SUM(Sheet1[SUM])
)
return
MEDIANX(
    FILTER(
        tab,
        [Y]=2018
    ),
    [Re]
)

 

 

 

median 2019 = 
var tab = 
SUMMARIZE(
    Sheet1,
    Sheet1[Product],
    Sheet1[Project],
    Sheet1[Y],
    "Re",
    SUM(Sheet1[SUM])
)
return
MEDIANX(
    FILTER(
        tab,
        [Y]=2019
    ),
    [Re]
)

 

 

Result:

f1.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @Kpham 

 

Based on your description, you may create a calculated column and two measures as below. The pbix file is attached in the end.

Calculated column:

 

Y = YEAR([Year])

 

 

Measure:

 

median 2018 = 
var tab = 
SUMMARIZE(
    Sheet1,
    Sheet1[Product],
    Sheet1[Project],
    Sheet1[Y],
    "Re",
    SUM(Sheet1[SUM])
)
return
MEDIANX(
    FILTER(
        tab,
        [Y]=2018
    ),
    [Re]
)

 

 

 

median 2019 = 
var tab = 
SUMMARIZE(
    Sheet1,
    Sheet1[Product],
    Sheet1[Project],
    Sheet1[Y],
    "Re",
    SUM(Sheet1[SUM])
)
return
MEDIANX(
    FILTER(
        tab,
        [Y]=2019
    ),
    [Re]
)

 

 

Result:

f1.png

 

Best Regards

Allan

 

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

darentengmfs
Post Prodigy
Post Prodigy

@Kpham 

 

You can sum your customer by year using Group By in Power Query.

 

Then to calculate median, you can use the median function.

 

https://docs.microsoft.com/en-us/dax/median-function-dax

 

Thanks but I didn't work.  I have uploaded the pbix to the post.

@Kpham 

 

Please try using Group By on Product, Project, and Year, with the result SUM of Cost.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.