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
Anonymous
Not applicable

Cumulative Sum by Person by Week during the Year DAX

Hello, PBI Experts!

 

Could you, please, help me with such issue...

I have a table with Time Entries for a large number of users. This information also includes TimeEntryID, TaskID, Entry Date, Task Duration, Week Day, Week Number, Entry Year and Month and etc.

 

I want to calculate a cumulative sum of duration hours per user per week (ISO week) in order to find the day of the week where this sum for the user is > 40 and to say on which day of the week this overtime appears.

 

The dataset in big but just to show an example:

 

 

Time Entry IDUser IDUser NameEntry DateEntry Week NumEntry YearEntry Week DayDuration
11A1/1/20181201810.5
21A1/1/20181201810.7
31A1/2/20181201821.5
41A1/2/20181201822.5
51A1/3/20181201833.5
61A1/4/20181201844.5
71A1/5/20181201851
81A1/6/20181201862
91A1/9/20182201829.5
101A1/9/201822018210.5
111A1/10/20182201830.4
121A1/10/20182201833
131A1/10/20182201834
141A1/10/20182201835
151A1/11/20182201843
161A1/11/20182201840.5
172B1/2/20181201820.7
182B1/2/20181201821.5
192B1/2/20181201822.5
202B1/2/20181201823.5
212B1/2/20181201824.5
222B1/3/20181201831
232B1/4/20181201842
242B1/5/20181201859.5
252B1/6/201812018610.5
262B1/1/20181201810.4
272B1/1/20181201813
282B1/9/20182201824
292B1/10/20182201835
302B1/11/20182201843

 

As a result I want to see the following Calculated Column:

 

User IDUser NameEntry DateEntry Week NumEntry YearEntry Week DayDurationCumSum
1A1/1/20181201810.50.5
1A1/1/20181201810.71.2
1A1/2/20181201821.52.7
1A1/2/20181201822.55.2
1A1/3/20181201833.58.7
1A1/4/20181201844.513.2
1A1/5/2018120185114.2
1A1/6/2018120186216.2
1A1/9/20182201829.59.5
1A1/9/201822018210.520
1A1/10/20182201830.420.4
1A1/10/2018220183323.4
1A1/10/2018220183427.4
1A1/10/2018220183532.4
1A1/11/2018220184335.4
1A1/11/20182201840.535.9
2B1/2/20181201820.70.7
2B1/2/20181201821.52.2
2B1/2/20181201822.54.7
2B1/2/20181201823.58.2
2B1/2/20181201824.512.7
2B1/3/2018120183113.7
2B1/4/2018120184215.7
2B1/5/20181201859.525.2
2B1/6/201812018610.535.7
2B1/1/20181201810.436.1
2B1/1/2018120181339.1
2B1/9/201822018244
2B1/10/201822018359
2B1/11/2018220184312

 

Will appreciate any valuable information.

Thanks a lot!

1 ACCEPTED SOLUTION
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Try this formula, please.

CumSum =
CALCULATE (
    SUM ( Table1[Duration] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[User Name], Table1[Entry Week Num] ),
        'Table1'[Entry Week Day] <= EARLIER ( Table1[Entry Week Day] )
            && Table1[Time Entry ID] <= EARLIER ( Table1[Time Entry ID] )
    )
)

Cumulative_Sum_by_Person_by_Week_during_the_Year_DAX

 

Best Regards,

Dale

Community Support Team _ Dale
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

4 REPLIES 4
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Try this formula, please.

CumSum =
CALCULATE (
    SUM ( Table1[Duration] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[User Name], Table1[Entry Week Num] ),
        'Table1'[Entry Week Day] <= EARLIER ( Table1[Entry Week Day] )
            && Table1[Time Entry ID] <= EARLIER ( Table1[Time Entry ID] )
    )
)

Cumulative_Sum_by_Person_by_Week_during_the_Year_DAX

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Big thanks, @v-jiascu-msft!!!

 

I expect to see something similar in the end but could you, please, explain, why Week Num and User Name are in ALLExcept section and Week Day and Time Entry Id participate in EARLIER calculations. Just don't get this point.

 

All in all, thanks alot for you reply.

It's my pleasure. @Anonymous.

 

You still can use this one which has a clearer logic. 

CumSum 2 =
VAR currentWeekDay = [Entry Week Day]  // the mean is as its name.
VAR currentTimeID = [Time Entry ID]
RETURN
    CALCULATE (
        SUM ( Table1[Duration] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[User Name], Table1[Entry Week Num] ),
            'Table1'[Entry Week Day] <= currentWeekDay
                && Table1[Time Entry ID] <= currentTimeID
        )
    )

The main difference here is the Row context in the data table while it's Filter context in a visual. ALLEXCEPT converts the row context into the filter context and clear other contexts except Table1[User Name] and Table1[Entry Week Num].

 

Best Regards,

Dale

 

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

thansk, @v-jiascu-msft.

 

Now it's clearer after your explanation. 

 

Appreciate your help. 

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.