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
WTAS80486
Helper IV
Helper IV

Calculate cumulative Total hours based on ID and date

Hi,

 

I am trying to calculate cumulative of total hours based on ID and Date

 

Cumulative Run Hours = CALCULATE( SUM('Table'[Hours]),
FILTER(
ALL('Table'[ ID]),
'Table'[Date] <=MAX('Table'[Date)]
)
))
 
Nothing seems to work. ALL, ALLEXCEPT, EARLIER

 

IDDateHoursCumulative
A11/9/2021   33
A12/1/2021   69
A1/2/2022   918
B2/3/2022   22
B3/4/2022   46
B4/5/2022   816
C5/3/2022   33
C6/2/202247
C7/1/2022414

Can someone please help.

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @WTAS80486 ,

According to your description, here's my solution.

Create a Date table.

Date = CALENDAR(DATE(2021,1,1),DATE(2022,12,31))

Create relationship between the two tables with the Date column. Then create a measure.

Cumulative =
CALCULATE (
    SUM ( 'Table'[Hours] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[ID] = MAX ( 'Table'[ID] )
            && 'Table'[Date] <= MAX ( 'Date'[Date] )
    )
)

Get the result.

vkalyjmsft_0-1660725651220.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

View solution in original post

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @WTAS80486 ,

According to your description, here's my solution.

Create a Date table.

Date = CALENDAR(DATE(2021,1,1),DATE(2022,12,31))

Create relationship between the two tables with the Date column. Then create a measure.

Cumulative =
CALCULATE (
    SUM ( 'Table'[Hours] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[ID] = MAX ( 'Table'[ID] )
            && 'Table'[Date] <= MAX ( 'Date'[Date] )
    )
)

Get the result.

vkalyjmsft_0-1660725651220.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

 

WTAS80486
Helper IV
Helper IV

I am trying to solve the same thing on measure from another table and get cumulative counts of failures based on month in another column of another table. But getting error

Hi @WTAS80486 ,

 

So what are the error you encountered? Do you have sample data from another table or a PBIX file (without private data)?

 

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

Best regards.

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Cumulative Run Hours =
IF (
    HASONEVALUE ( 'Table'[ID] ),
    CALCULATE (
        SUM ( 'Table'[Hours] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[ID] ),
            'Table'[Date] <= MAX ( 'Table'[Date] )
        )
    )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thanks for the reply!

 

This dosents seem to work on my data.

 

I used this:

 

Culmulative hours = CALCULATE (
                SUM('Table'[Hours]),
                FILTER (
                    ALL ( 'Table'),
                    'Table'[ ID] = EARLIER ( 'Table'[ ID] )
                        && 'Table'[Date]<= EARLIER ('Table'[Date])
                )
            )
WTAS80486
Helper IV
Helper IV

I solved this by:

 

Culmulative hours = CALCULATE (
                SUM('Table'[Hours]),
                FILTER (
                    ALL ( 'Table'),
                    'Table'[ ID] = EARLIER ( 'Table'[ ID] )
                        && 'Table'[Date]<= EARLIER ('Table'[Date])
                )
            )

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