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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

DATEDIFF With Month Filter

Hello my colleagues!

 

My problem is:

 

I need to calculate the time difference between dates, starting at 06/01/2020 and ending at "NOW". However, I need this calculation to respect the hour limit of the month, but also be cumulative.

 

How i'm calculating now:

 

Currently, my equation is as follows:

Spoiler
TimeNow = DATEDIFF (DATE (2020,06,01), NOW (), HOUR)

The problem in this formula is:

 

I need every month that passes, those hours accumulate since 06/01/2020, but stop at the end of the month where there was a maintenance register.

 

My formula will start at June, and the difference in this month is only from 06/01/2020 to 06/30/2020. However for July that is cumulative, from 06/01/2020 to 07/31/2020, For August from 06/01/2020 to 08/31/2020 and so on.

 

My database have the following data, and the DATEDIFF is what i want to create:

 

EquipmentBreakdown StartBreakdown EndDATEDIFF to NOW (Hours)
A03/06/2020 09:05:0003/06/2020 15:00:00730
B15/06/2020 10:15:0015/06/2020 12:00:00730
C08/07/2020 12:00:0008/07/2020 13:00:001185 (Max is 1460, two months)


How can i solve this question? Can be in DAX or Query.

 

Thanks for the help!

5 REPLIES 5
Anonymous
Not applicable

It's not clear at all what you want to do... "respect the hour limit of the month" - please define what you mean by this.

Best
D
AntrikshSharma
Super User
Super User

Here is a general pattern for running total calculations:

Running Total = 
VAR MaxDateInFilterContext =
    MAX ( Dates[Date] )
VAR MaxYear =
    YEAR ( MaxDateInFilterContext )
VAR DatesLessThanMaxDate =
    FILTER (
        ALL ( Dates[Date], Dates[Calendar Year Number] ),
        Dates[Date] <= MaxDateInFilterContext
            && Dates[Calendar Year Number] = MaxYear
    )
VAR Result =
    CALCULATE (
        [Total Sales],
        DatesLessThanMaxDate
    )
RETURN
    Result
Anonymous
Not applicable

Hello Antriksh Sharma!

 

Could you explain me the steps of this calculation?

mahoneypat
Microsoft Employee
Microsoft Employee

What do you mean by "hour limit of the month"?  Can you provide example data table and desired output, so a solution can be suggested?

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hello my friend, post edited with the data table example.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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