Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DAX/PowerBI - Sum for each day

Tags:

sum

powerbi

dax

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.

like image 754
SUMguy Avatar asked Oct 25 '25 12:10

SUMguy


1 Answers

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

like image 149
Foxan Ng Avatar answered Oct 27 '25 20:10

Foxan Ng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!