3
votes

I have a table which contains a row for each day and number of hours an employee is employed.

Table 1

 Employee    Task     Hours     Date         Sum (what I'm looking for)
 A           123      4         1/1/2017     8
 A           403      4         1/1/2017     8
 B           123      3         1/1/2017     8
 B           656      5         1/1/2017     8
 A           303      1         1/2/2017     7
 A           123      6         1/2/2017     7

What I am trying to do is take the sum of the Hours column grouped by Date. In other words, I want the sum of the Hours column where the Date = Date in the current row.

2

2 Answers

3
votes

What you need is the EARLIER function.

The DAX for the calculated column is as follows:

Sum = 
CALCULATE(
    SUM(Table1[Hours]),
    FILTER(
        ALL(Table1) ,
        Table1[Employee] = EARLIER(Table1[Employee]) &&
        Table1[Date] = EARLIER(Table1[Date])
    )
)

Result:

result

1
votes

I don't think it's possible to make a new column, but you can achieve this using a measure.

Use the below DAX to create a measure and then use that in your visuals.

Sum = CALCULATE(Sum(Table1[Hours]), FILTER(ALL(Table1), Table1[Employee] = MAX(Table1[Employee]) && Table1[Date] = MAX(Table1[Date])))