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
scaballerom
Helper I
Helper I

Rolling Median Time Period

Hi all,

 

I need to dynamically calculate the median of the last three months of the starting time of the distinct jobs of the current selected date, that is:

scaballerom_0-1671123748381.png

I want to calculate, for each distinct job key, the median of its "Start" time of the last three months.

 

I tried:

 

MedianStartingL3M =
VAR NumberOfDays = 91
VAR MaxDay = SELECTEDVALUE('Fact Jobs'[job_start_datetime])
VAR MinDay = MaxDay-NumberOfDays
VAR Result =
        CALCULATE(PERCENTILE.EXC('Fact Jobs'[job_start_time],0.5),ALL('Fact Jobs'),'Fact Jobs'[job_key]=SELECTEDVALUE('Fact Jobs'[job_key]),'Fact Jobs'[job_start_datetime]<=MaxDay,'Fact Jobs'[job_start_datetime]>MinDay)
RETURN
Result
 
Where
job_start_time = time when the job starts. In the first example: 14:28:49
job_key = unique identifier of the job
job_start_datetime = datetime when the job starts. In the first example 15/12/2022 14:28:49
 
But it's not working

 

Could someone help me out?

 

Thanks in advance for your help.


BR,

Sara

2 REPLIES 2
v-jialluo-msft
Community Support
Community Support

Hi  @scaballerom ,

 

You can try this measure:

 

MEASURE = 
CALCULATE (
    PERCENTILE.EXC ( 'Fact Jobs'[job_start_time], 0.5 ),
    FILTER (
        ALL ( 'Fact Jobs' ),
        'Fact Jobs'[job_key] = SELECTEDVALUE ( 'Fact Jobs'[job_key] )
            && 'Fact Jobs'[job_start_datetime] <= MaxDay
            && 'Fact Jobs'[job_start_datetime] > MinDay
    )
)

 

If that's not what you need, provide sample files and expected output.

How to provide sample data in the Power BI Forum - Microsoft Power BI Community

 

Best Regards,

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

Hi @v-jialluo-msft ,

 

I get the following error:

scaballerom_0-1671190565438.png

Please find bellow some sample data, as the expected results:

 

job_namejob_starting_time_adjjob_statusjob_starting_datetime_adj   
118:00:01Completed15/09/2022 18:00   
118:00:09Completed18/09/2022 18:00 Median18:00:09
118:00:01Completed19/09/2022 18:00 Average18:00:08
118:00:01Completed20/09/2022 18:00   
118:00:07Completed21/09/2022 18:00   
118:00:09Completed22/09/2022 18:00   
118:00:14Completed25/09/2022 18:00   
118:00:12Completed26/09/2022 18:00   
118:00:03Completed27/09/2022 18:00   
118:00:13Completed28/09/2022 18:00   
118:00:18Completed29/09/2022 18:00   
118:00:07Completed02/10/2022 18:00   
118:00:15Completed03/10/2022 18:00   

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.

Top Solution Authors