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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Josee
Regular Visitor

optimisation of mobile median in dax

Hello,

 

I would like to optimise the calculation below. I guess if function or switch function would be helpfull. 
Do you have any recommandation ?

MobileMedian3period=

= ( calculate( MEDIAN(waitingtable[nNb_days_waiting_total]), filter(table_year_period, table_year_period[no_periode(row)]=1))
+ calculate(MEDIAN(waitingtable[nNb_days_waiting_total]), filter(table_year_period, table_year_period[no_periode(row)]=2))
+ calculate(MEDIAN(waitingtable[nNb_days_waiting_total]), filter(table_year_period, table_year_period[no_periode(row)]=3))
)/3
4 REPLIES 4
Josee
Regular Visitor

Hello, 

This code is more efficient and leaner:
1) creation of a measure 

med_waiting = MEDIAN(waitingtable[nMb_days_waiting_total])

2) creation of this second measure

MobileMedian3period =

VAR MedM = CALCULATE(

AVERAGEX(

VALUES(table_year_period[no_periode(row)]),

[Med_waiting]

),

table_an_periode[no_periode(row)] <= 3

)

RETURN MedM

Josee
Regular Visitor

My waiting list don't have the same number of observations by period. To calculate a mobile median(mean of the 3 median), I need to calculate independently the median for these last 3 periods.
( I also perform the same for 13 period/a year). 
It would be more effective if the calculation could go through all observation once or, until it is used like a else if .

Hi @Josee ,

If that wasn't the solution you were looking for, please provide a sample data and your expected result. Here's a guide on how the community can better answer your queries: https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523#M6071... 










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
danextian
Super User
Super User

Hi @Josee ,

You can actually add an or statement in filter so you can write your measuer this way:

MobileMedian3period =
DIVIDE (
    CALCULATE (
        MEDIAN ( waitingtable[nNb_days_waiting_total] ),
        FILTER (
            table_year_period,
            table_year_period[no_periode(row)] >= 1
                || table_year_period[no_periode(row)] <= 3
        )
    ),
    3
)









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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.