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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
manelfera
Regular Visitor

Help with getting best race pace for each driver

I am using power bi to extract some information of best lap times for my sim racing league. 

Now I want to know how can I get the best race pace for each of the drivers.

The race pace is considered when a driver has 3 consecutive laps without cuts. I tried to create a calculated column on which store the time for each row + the 2 following times, but I haven't succeeded.

An example of how the lap times are stored is the following table:

DateLapTimeMillisDriverCutsRace pace
01/12/2022 22:00 85000

Driver A

0null (no 3 consecutive clean laps)
01/12/2022 22:02 86000Driver A1null (no 3 consecutive clean laps)
01/12/2022 22:04 85000Driver A0(85000 + 87000 + 86000)/3
01/12/2022 22:0484000Driver B0(84000 + 86000 + 85000)/3
01/12/2022 22:0686000Driver B0null (no 3 consecutive clean laps)
01/12/2022 22:07 87000Driver A0null (no 3 consecutive clean laps)
01/12/2022 22:08 85000Driver B0null (no 3 consecutive clean laps)
01/12/2022 22:0986000Driver A0null (no 3 consecutive clean laps)

 

Date column is used to sort laps for each driver.

Anyone can help with this?

 

Sample data:

https://1drv.ms/x/s!AmH97gz_o34L-aVirzuEbdYqGy6S8A?e=pflRp5 

3 REPLIES 3
manelfera
Regular Visitor

I share here a copy of the table on which I am working, so there is more data and might be easy to have a solution.

 

https://1drv.ms/x/s!AmH97gz_o34L-aVirzuEbdYqGy6S8A?e=pflRp5 

 

The column Lap is the number of lap of each driver, as I have sorted them and set the number. So there might be an easy way with lap number, cuts, laptime (or laptimemillis) and driver. But I don't know what to do.

ppm1
Solution Sage
Solution Sage

Please try this measure expression. The RAND is there to break any ties in case two laps have exact same time (so only 3 rows included in average).

Avg Last 3 No Cuts =
VAR vThisDT =
    MAX ( Laps[Date] )
VAR vLastCutTime =
    CALCULATE (
        MAX ( Laps[Date] ),
        ALLEXCEPT ( laps, Laps[Driver] ),
        Laps[Date] <= vThisDT,
        Laps[Cuts] > 0
    )
VAR vTop3NoCuts =
    CALCULATETABLE (
        TOPN ( 3, Laps, Laps[LapTimeMillis], ASC, RAND (), ASC ),
        ALLEXCEPT ( laps, Laps[Driver] ),
        Laps[Date] > vLastCutTime
            && Laps[Date] <= vThisDT
    )
VAR vResult =
    IF (
        COUNTROWS ( vTop3NoCuts ) = 3,
        AVERAGEX ( vTop3NoCuts, Laps[LapTimeMillis] ),
        "Not 3 laps"
    )
RETURN
    vResult

ppm1_0-1670109753369.png

 

Pat

 

Microsoft Employee

Hi, I have 2.000 records with data from 9 drivers and it's just calculating results for 3 drivers, for the others it's not giving any output, and they have consecutive valid laps. What might be wrong?

I have updated what you told me to this, so I could add as a column. Having it as a measure it only returns me 2 values with valid laps.

 

 

AvgRacePaceMillis = 
VAR vThisDT =
    MAX ( 'Main Results'[Timestamp] )
VAR vLastCutTime =
    CALCULATE (
        MAX ( 'Main Results'[Timestamp] ),
        ALLEXCEPT ( 'Main Results', 'Main Results'[Drivers.name] ),
        'Main Results'[Timestamp] <= vThisDT,
        'Main Results'[Cuts] > 0
    )
VAR vTop3NoCuts =
    CALCULATETABLE (
        TOPN ( 3, 'Main Results', 'Main Results'[LapTimeMillis], ASC, RAND (), ASC ),
        ALLEXCEPT ( 'Main Results', 'Main Results'[Drivers.name] ),
        'Main Results'[Timestamp] > vLastCutTime
            && 'Main Results'[Timestamp] <= vThisDT
    )
VAR vResult =
    IF (
        COUNTROWS ( vTop3NoCuts ) = 3,
        AVERAGEX ( vTop3NoCuts, 'Main Results'[LapTimeMillis] ),
        BLANK()
    )
RETURN
    vResult

 

 

Also, in this particular case if 2 valid laps have the same time it doesn't matter, it is ok to sum 3 valid laps even if 2 have the same exact time.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors