The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I am trying to create a running total using WINDOW function and I am not sure if I am overcomplicating but this is the only I can get it to work.
//my base data is this
| Year | Val |
|------|-----|
| 2020 | 100 |
| 2021 | 200 |
| 2022 | 300 |
| 2023 | 400 |
//I need a calculated table with running total
| Year | Val | rnt |
|------|-----|------|
| 2020 | 100 | 100 |
| 2021 | 200 | 300 |
| 2022 | 300 | 600 |
| 2023 | 400 | 1000 |
I am writing a table expression like this which is doing the job. The rank is calculated to determine the correct TO parameter of WINDOW. Is there an easier way?
Table =
ADDCOLUMNS (
tbl,
"rnt",
VAR toVal =
RANKX (
WINDOW ( 1, ABS, -1, ABS, SUMMARIZE ( tbl, tbl[Year] ), ORDERBY ( tbl[Year] ) ),
tbl[Year],
,
DESC
)
VAR rnt =
CALCULATE (
SUM ( tbl[Val] ),
ALL ( tbl ),
WINDOW ( 1, ABS, toVal * -1, ABS, , ORDERBY ( tbl[Year], ASC ) )
)
RETURN
rnt
)
@AlexisOlson @CNENFRNL @jeffrey_wang
Thank you in advance
Solved! Go to Solution.
Here is a simpler solution
Here is a simpler solution
User | Count |
---|---|
69 | |
64 | |
62 | |
55 | |
28 |
User | Count |
---|---|
203 | |
82 | |
65 | |
48 | |
38 |