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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Jake0001
Frequent Visitor

Get Median for each row and subtract for each column

Dear all,

I would like to ask for assistance with an issue I am encountering on POWER BI, specifically with a particular DAX query. I aim to create a formula to calculate the median (not considering 0 or blank) for each product (MILK, BREAD.....) and then subtract it from the price for each country (ITALY JAPAN) to understand the deviation. 

 

The following one is the data set (in this case for example is characterized by one product but in reality, i have more products):

 

PRODUCT LOCATIONPRICE
MILKITALY6
MILKUSA4
MILKJAPAN2
MILKSPAIN7
MILKGERMAN2

 

The result I would like to see is the following one (PRODUCT on row, LOCATION on column):

 

 ITALY USA JAPAN SPAIN GERMAN 
 PRICEDELTAPRICEDELTAPRICEDELTAPRICEDELTAPRICEDELTA
MILK6240227-322

 

MEDIAN: 4

DELTA= PRICE(EACH COUNTRY) - MEDIAN(EACH PRODUCT)

 

Is there any dax could help me to calculate the delta in this visualization? 

 

Thanks in advance!

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

lbendlin_0-1706281585422.png

DELTA = sum('Table'[PRICE])-CALCULATE(MEDIANX('Table','Table'[PRICE]),REMOVEFILTERS('Table'[LOCATION]))

View solution in original post

@Jake0001 

instead of removefilters , use allselected('table'[location] ) 

 

hope this helps .

 

 

 

If my answer helped sort things out for you, feel free to give it a thumbs up and mark it as the solution! It makes a difference and might help someone else too. Thanks for spreading the good vibes! 👍🤠

View solution in original post

6 REPLIES 6
Jake0001
Frequent Visitor

Thank you @lbendlin and @Daniel29195 ! Right now the dynamic median (excluding blank and 0) is implemented in my Bi report and the code is the following one (for who needs any helps):

DYNAMIC MEDIAN =
CALCULATE (
    MEDIANX(
        FILTER('table', 'table'[price] <> BLANK() && 'table'[price] <> 0),
        'table'[price]
    ),
    ALLSELECTED('table'[location])
)
 
 DELTA = sum('Table'[PRICE])-[DYNAMIC MEDIAN]
lbendlin
Super User
Super User

lbendlin_0-1706281585422.png

DELTA = sum('Table'[PRICE])-CALCULATE(MEDIANX('Table','Table'[PRICE]),REMOVEFILTERS('Table'[LOCATION]))

Ibendlin, thanks for the advise. However, I would like to calculate a dynam median based on the slicer location in the visual. In this configuration, the slicer Location doesn't affect the median due to REMOVEFILTERS. In your opinion, is it possible to do something like this? 

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

@Jake0001 

instead of removefilters , use allselected('table'[location] ) 

 

hope this helps .

 

 

 

If my answer helped sort things out for you, feel free to give it a thumbs up and mark it as the solution! It makes a difference and might help someone else too. Thanks for spreading the good vibes! 👍🤠

REMOVEFILTERS and ALLSELECTED are equivalent when applied to the same column.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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