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
jaymccorp
Frequent Visitor

Running total with date reset

I am trying to do a fatigue calculation that does a running total of hours worked, and days in a row, but it resets when the person does not come in for work for one day.  I have looked at the past posts, and can get the running total, but I do not know how to get the sum to restart when the person does not come in.  This is what I want it do to:

 

DateEmployee NumberTime - HoursFatigue Hrs - running totalDays in row
6/19/1810027.427.421
6/20/1810027.9215.342
6/21/1810021.1816.523
6/23/1810021.731.731
6/24/1810020.972.72
6/25/1810021.273.973
7/2/1810025.085.081
7/10/1810020.650.651
7/11/1810023.54.152
7/13/1810021.651.651
6/18/1810049.779.771
6/19/1810049.719.472
6/20/18100411.6731.143
6/21/1810049.640.744
6/22/1810048.1248.865
6/23/181004149.866
6/25/1810049.79.71
6/26/1810049.8319.532
6/27/1810049.6529.183
6/28/1810049.6538.834
7/2/1810049.839.831
7/3/1810049.7219.552
7/5/1810049.639.631
7/6/1810048.718.332
7/7/181004119.333
7/10/1810049.789.781
7/11/1810049.7719.552
7/12/1810049.629.153
7/13/1810048.4837.634
7/14/181004239.635

 

Thanks in advance for your help.  This is my first post, but I have read a lot of different posts on MANY different questions.  It has been very helpful.  Great forum!

1 ACCEPTED SOLUTION

@jaymccorp

 

Please see the attached file with your sample data and above calculated columns

 

rnnin.png


Regards
Zubair

Please try my custom visuals

View solution in original post

6 REPLIES 6
Zubair_Muhammad
Community Champion
Community Champion

@jaymccorp

 

If you already have a days in a row column

 

you can use this calculated column to get the running total that resets

 

Running Total =
VAR mydays = [Date] - [Days in row]
    + 1
RETURN
    SUMX (
        FILTER (
            Table1,
            [Employee Number] = EARLIER ( [Employee Number] )
                && [Date] <= EARLIER ( [Date] )
                && [Date] >= mydays
        ),
        [Time - Hours]
    )

Regards
Zubair

Please try my custom visuals

Thanks, but I do not have days in a row either.  I am tying to create the two last columns.  I have been able to get a running sum for hours, but I need it to reset when the person does not come to work for one day.  The count and the running total will then reset and start again once the person takes a day off. 

 

Thanks for the help!

@jaymccorp

 

In that case, to get the Days in a Row column we can first add a supporting column which determines when running total is reset

 

FindCounterReset =
VAR PreviousDate =
    MINX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Employee Number] = EARLIER ( [Employee Number] )
                    && [Date] < EARLIER ( [Date] )
            ),
            [Date], DESC
        ),
        [Date]
    )
RETURN
    IF ( [Date] <> PreviousDate + 1, "Counter reset" )

 

Now we can add the Days in Row Column as follows

 

Days in a Row =
VAR counterstart =
    MINX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Employee Number] = EARLIER ( [Employee Number] )
                    && [Date] <= EARLIER ( [Date] )
                    && [FindCounterReset] = "Counter reset"
            ),
            [Date], DESC
        ),
        [Date]
    )
VAR counterend_ =
    MINX (
        TOPN (
            1,
            FILTER (
                Table1,
                [Employee Number] = EARLIER ( [Employee Number] )
                    && [Date] > EARLIER ( [Date] )
                    && [FindCounterReset] = "Counter reset"
            ),
            [Date], ASC
        ),
        [Date]
    )
VAR counterend =
    IF ( counterend_ = BLANK (), DATE ( 3000, 1, 1 ), counterend_ )
RETURN
    RANKX (
        FILTER (
            Table1,
            [Employee Number] = EARLIER ( [Employee Number] )
                && [Date] >= counterstart
                && [Date] < counterend
        ),
        [Date],
        ,
        ASC,
        DENSE
    )

 

Now you can use the Column for running total in the previous post


Regards
Zubair

Please try my custom visuals

@jaymccorp

 

Please see the attached file with your sample data and above calculated columns

 

rnnin.png


Regards
Zubair

Please try my custom visuals

That is AMAZING!  It works!!  Now I have to study it for a couple of hours to understand why.

 

THANKS A LOT!!

Shelley
Continued Contributor
Continued Contributor

@Zubair_Muhammad I am trying to do something similar, but want the cumulative total per contract to reset at the end of the contract.

I have contract data like this:

CONTRACT INPUTS    
BPIDCustomer Name (BPID)contract_numSAP Contract StartSAP Contract EndContract Cap
399ABC COMPANY (399)80036564092/1/20181/31/2019 $    8,000.00
399ABC COMPANY (399)80040815792/1/20191/31/2020 $  10,000.00
399ABC COMPANY (399)80045755892/1/20201/31/2021

 $    9,000.00

 

And then I have transaction data. I want to plot the contract cap, which I figured out how to do, AND the cumulative data.

DATA INPUTSDATA INPUTSDESIRED RESULT 
    
Order Submit DateList_PriceCumulative UsageNotes
2/1/2018 0Usage begins at 0 on 2/1/18, which is start of the contract above
2/21/2018$2,592$2,592 
8/23/2018$1,542$4,134 
10/12/2018$1,709$5,843 
10/17/2018$3,893$9,736 
12/4/2018$513$10,249 
2/1/2019 $0Usage begins at 0 again on 2/1/19, with a new contract
2/25/2019$2,940$2,940 
5/14/2019$1,186$4,126 
7/18/2019$0$4,126 
8/23/2019$323$4,449 
9/2/2019$545$4,994 
9/24/2019$2,636$7,630 
2/1/2020 $0Usage begins again at 0 on 2/1/20
2/7/2020$1,737$1,737 
2/19/2020$128$1,865 
2/20/2020$128$1,993 

 

The repair entitlements (blue line) plot correctly, but the cumulative value (red line) keeps accumulating instead of resetting to 0 at the start of a new contract.

 

Here are my formulas:

Repair Entitlement Amount =
CALCULATE(SUM('Entitlements'[Repair Cap]),
FILTER('QBContract','QBContract'[SAP Contract Start] <= MAX('RA_Daily_Calendar'[Date]) &&
'QBContract'[SAP Contract End] >= MAX('RA_Daily_Calendar'[Date])))
 
I know this will not work, but does accumulate:
List_Price running total in Fiscal_YearMonth =
CALCULATE(
    SUM('RepairTransaction'[List_Price]),
    FILTER(
        ALLSELECTED('RA_Daily_Calendar'[CalendarYear-Mo]),
        ISONORAFTER('RA_Daily_Calendar'[CalendarYear-Mo], MAX('RA_Daily_Calendar'[CalendarYear-Mo]), DESC)))
 

For this one I was trying to use the contract dates, but it does not accumulate, it only shows points in time for each repair (orange dots below).

Repair Amount List Price =
CALCULATE(SUM('RepairTransaction'[List_Price]),
FILTER(ALL('RepairTransaction'[Order_Submit_Date]), 'RepairTransaction'[Order_Submit_Date] >= MAX('QBContract'[SAP Contract Start]) &&
'RepairTransaction'[Order_Submit_Date] <= MAX('QBContract'[SAP Contract End])))
 

Annotation 2020-03-18 163704.png

 

Annotation 2020-03-18 163704b.png

 

Any help is appreciated. Thanks!

 

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.