cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Michella
Helper I
Helper I

median of metric per category when metric > 0

Hi everyone,

 

I need help, please.

 

I have two tables in a datamodel connected via sailingKey which is a unique identifier. They have crossfiltering enabled, as seen here:

 Michella_0-1686669387295.png

 

In the data I have different itineraries (e.g. from A-B and C-D, ...). Each itinerary consists of multiple sailing keys.

I want to calculate the median of the metric for each itinerary but only for those sailing keys that have a value greater than 0 in the metric. The metric comes from the shipreadings table, everything else from dimsailing. 

 

I have a partially working formula which changes based on what I filter but I do not want the number to change:

 

 

Median per Itinerary = 

IF(ISBLANK([Metric]), BLANK(),
    DIVIDE(
        MEDIANX (
            SUMMARIZE (
                ALLSELECTED(shipreadings), shipreadings[SailingKey],
                "Sales_Calc", [Metric] 
            ),
            [Sales_Calc]
        ), 2
    ) 
)

 

 

This is how the formula behaves now:


Example when I filter for Itinerary A-B

showing the median of the filtered rows

 

itinerarySailingKeymetricMedian of Metric
A-B12341012
A-B23452512
A-B34561212

 

 

 

Example when I do not filter: 

Showing the median of all the rows, not per itinerary

 

itinerarySailingKeymetricMedian of Metric
A-B12341015
A-B23452515
A-B34561215
C-D45671215
C-D56783015
C-D67891815

 

What I expect with the formula to happen:

If I do not select any filter, I want the formula to still show median of metric per itinerary (if metric is not blank or 0, in that case the median should not be shown on that row)

itinerarySailingKeymetricMedian of metric
A-B12341012
A-B23452512
A-B34561212
C-D45671218
C-D56783018
C-D67891818

 

like having the median frozen, regardless of other filters on the page. 

 

Thanks, Michella

 

1 ACCEPTED SOLUTION
Michella
Helper I
Helper I

Hi @Ibendlin.

 

I have found a solution on the internet: 

 CALCULATE (
        MEDIANX( 
            VALUES ( shipreadings[SailingKey]),
            [TotalFuel]
        ),
        ALLEXCEPT( dimsailing, dimsailing[itinerary] )
    )

 

View solution in original post

2 REPLIES 2
Michella
Helper I
Helper I

Hi @Ibendlin.

 

I have found a solution on the internet: 

 CALCULATE (
        MEDIANX( 
            VALUES ( shipreadings[SailingKey]),
            [TotalFuel]
        ),
        ALLEXCEPT( dimsailing, dimsailing[itinerary] )
    )

 

lbendlin
Super User
Super User

They have crossfiltering enabled

please provide your reasoning for that decision

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors