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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
alisoroush77777
New Member

find the difference date between two unique car number

hi

I have a table that has 2 columns in it. one is car number and another is repair date. I have 5 car that is repaired regularly and each time the car number and repair date is addet into this table considering that each row represent one repair for one car number. Now I want to calculate the average time (day) between two repair for each car number.

How can I implement this in power BI? With DAX or M?

Any comment is appreciated.

3 REPLIES 3
johnt75
Super User
Super User

You need to update your version of Power BI desktop. ROWNUMBER is fairly new but OFFSET was in the December release.

johnt75
Super User
Super User

You will need a column which uniquely identifies each row. If you don't have one already you can use Power Query to add an index column. In the modelling view you need to select the table and mark the unique column as the key column for the table.

Then you could create a measure like

Avg days between repair =
AVERAGEX (
    'Table',
    VAR CurrentRow =
        ROWNUMBER (
            ALL ( 'Table' ),
            ORDERBY ( 'Table'[Repair date], ASC ),
            PARTITIONBY ( 'Table'[Car number] )
        )
    RETURN
        IF (
            CurrentRow > 1,
            VAR CurrentDate = 'Table'[Repair date]
            VAR PrevDate =
                SELECTCOLUMNS (
                    OFFSET (
                        -1,
                        ALL ( 'Table' ),
                        ORDERBY ( 'Table'[Repair date], ASC ),
                        PARTITIONBY ( 'Table'[Car number] )
                    ),
                    "@repair date", 'Table'[Repair date]
                )
            RETURN
                DATEDIFF ( PrevDate, CurrentDate, DAY )
        )
)

it seems that it does not recognize the functions

Annotation 2023-05-22 150337.jpg

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.