Hello,
I wanted to create a Running Total column in DAX.
I have an Invoice Table which looks like below:
Account ID | Invoice Date | Invoice Price | Running Total |
1 | 10/13/2016 | 50 | 50 |
1 | 12/10/2017 | 279 | 329 |
1 | 2/23/2018 | 1380 | 1709 |
2 | 4/15/2018 | 325 | 325 |
2 | 3/4/2019 | 787 | 1112 |
3 | 6/19/2018 | 2 | 2 |
4 | 9/10/2017 | 2356 | 2356 |
4 | 7/30/2018 | 35 | 2391 |
4 | 9/9/2018 | 254 | 2645 |
4 | 5/7/2019 | 756 | 3401 |
5 | 3/12/2017 | 37 | 37 |
5 | 8/26/2018 | 876 | 913 |
My SQL code for that is:
SELECT SUM(InvoicePrice) OVER (Partition by AccountID Order by InvoiceDate) asRunningTotal
FROM Invoices
Note: 1 account can have many invoices so I partitioned by account ID as I want to see running total for each account.