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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
sam0007
Frequent Visitor

DAX: Cummulative count per hour

Hi PBIX community,

I'm looking to show cummulative count in a table. The cummulative count works fine until 11PM but then it kind of goes awry. I have date and hour table as dimentions. Date and hour table are related to data table via inactive relationships. I have used 'userelationship' functions in my DAX to count instances by hour.

 

Attached is PBIX file and results that I'm expecting in an excel file.

 

* How do I navigate to resolve the cummulative total issue?

* Why is there a value of '8' in cumulative column on 13 July 2021?

* How can I get rid of cummulative data for 14 July 2021?

 

DAX for cummulative is:

Cummulative Eq Assign =
CALCULATE (
[TotalLoadWithEq],
USERELATIONSHIP ( f_DataTable[Eq Assign Date], d_DateTable[Date] ),
USERELATIONSHIP ( f_DataTable[Eq Assign Hour], d_HourTable[Time] ),
FILTER (
ALLSELECTED ( d_DateTable ),
d_DateTable[Date] <= MAX ( d_DateTable[Date] )
),
FILTER (
ALLSELECTED ( d_HourTable[Time] ),
d_HourTable[Time] <= MAX ( d_HourTable[Time] )
)
)

 

Any hints or tips to resolve this error would be helpful. Thanks a lot in advance!

 

https://www.dropbox.com/sh/l94j7rb9iavm783/AADqJs6dOZU06anbmdfftyiUa?dl=0

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

@sam0007 ,

I'm not sure this is the best implementation since I'm not aware about your real model and all the prerequisites, but you can try this option:

Cummulative Eq Assign_2 = 
VAR currentDate = MAX ( d_DateTable[Date] )
VAR currentTime = MAX ( d_HourTable[Hour of Day] )
VAR prevDayValue =
    IF (
        ISINSCOPE ( d_DateTable[Date] ),
        CALCULATE (
            [EqAssignPerHour],
            FILTER ( ALL ( d_DateTable[Date] ), d_DateTable[Date] < currentDate ),
            ALL ( d_HourTable[Hour of Day] )
        )
    )
VAR c_amt =
    CALCULATE (
        [EqAssignPerHour],
        FILTER (
            ALL ( d_HourTable[Hour of Day] ),
            d_HourTable[Hour of Day] <= currentTime
        )
    )
RETURN
    IF ( NOT ISBLANK ( [EqAssignPerHour] ), prevDayValue + c_amt )

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

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

5 REPLIES 5
sam0007
Frequent Visitor

That worked! Thank you!

sam0007
Frequent Visitor

Sorry, have a small issue here, on Tuesday 13 Jul 2021 cummulative column shows as 11 it should be 41 because:

Cummulative count 30 on Monday 12 Jul 2021 @ 11 PM

+

11 new equipment on Tuesday 13 Jul @ 1 AM.

resulting in 41 for cummulative column at 1AM.

 

Thanks!

ERD
Community Champion
Community Champion

@sam0007 ,

I'm not sure this is the best implementation since I'm not aware about your real model and all the prerequisites, but you can try this option:

Cummulative Eq Assign_2 = 
VAR currentDate = MAX ( d_DateTable[Date] )
VAR currentTime = MAX ( d_HourTable[Hour of Day] )
VAR prevDayValue =
    IF (
        ISINSCOPE ( d_DateTable[Date] ),
        CALCULATE (
            [EqAssignPerHour],
            FILTER ( ALL ( d_DateTable[Date] ), d_DateTable[Date] < currentDate ),
            ALL ( d_HourTable[Hour of Day] )
        )
    )
VAR c_amt =
    CALCULATE (
        [EqAssignPerHour],
        FILTER (
            ALL ( d_HourTable[Hour of Day] ),
            d_HourTable[Hour of Day] <= currentTime
        )
    )
RETURN
    IF ( NOT ISBLANK ( [EqAssignPerHour] ), prevDayValue + c_amt )

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

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

sam0007
Frequent Visitor

@ERD Thanks very much again! learning a lot from you. Cheers!

ERD
Community Champion
Community Champion

Hi @sam0007 ,

I didn't check the figures for other measures (as far as I've understood, you only have issues with cummulative measure) and according to your visual you can change the measure this way:

Cummulative Eq Assign_2 = 
VAR currentDate = MAX ( d_DateTable[Date] )
VAR currentTime = MAX ( d_HourTable[Hour of Day] )
VAR result =
    CALCULATE (
        [EqAssignPerHour],
        FILTER ( 
            ALLSELECTED ( d_DateTable[Date] ), 
            d_DateTable[Date] <= currentDate 
        ),
        FILTER (
            ALLSELECTED ( d_HourTable[Hour of Day] ),
            d_HourTable[Hour of Day] <= currentTime
        )
    )
RETURN
    IF ( NOT ISBLANK ( [EqAssignPerHour] ), result )

ERD_0-1626329343290.png

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

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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