Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi Team,
I have created a virtual table using DAX, I need to calculate a new column with the cumulative total using the virtual table.
Kindly suggest possibilities.
Thanks in Advance,
Solved! Go to Solution.
It may be better to do this with a measure instead of generated a running total in a variable, but here is an example that shows how to approach this. The first variable is just a table with Index and Value, and the 2nd variable shows how to add the RT column (you'll need a column that has a date, index, etc. to use for filtering). This is a table expression but you could return a scalar variable to return a calculation with the added column as a measure.
DemoTable =
VAR vTable =
DATATABLE (
"Index", INTEGER,
"Value", INTEGER,
{
{ 1, 2 },
{ 2, 4 },
{ 3, 6 }
}
)
VAR vAddRT =
ADDCOLUMNS (
vTable,
"RT",
VAR thisrowindex = [Index]
RETURN
SUMX ( FILTER ( vTable, [Index] <= thisrowindex ), [Value] )
)
RETURN
vAddRT
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
@mahoneypat Although you posted this three years ago, many thanks! I had been searching for this answer for hours!
It may be better to do this with a measure instead of generated a running total in a variable, but here is an example that shows how to approach this. The first variable is just a table with Index and Value, and the 2nd variable shows how to add the RT column (you'll need a column that has a date, index, etc. to use for filtering). This is a table expression but you could return a scalar variable to return a calculation with the added column as a measure.
DemoTable =
VAR vTable =
DATATABLE (
"Index", INTEGER,
"Value", INTEGER,
{
{ 1, 2 },
{ 2, 4 },
{ 3, 6 }
}
)
VAR vAddRT =
ADDCOLUMNS (
vTable,
"RT",
VAR thisrowindex = [Index]
RETURN
SUMX ( FILTER ( vTable, [Index] <= thisrowindex ), [Value] )
)
RETURN
vAddRT
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 37 | |
| 37 | |
| 33 | |
| 32 | |
| 29 |
| User | Count |
|---|---|
| 130 | |
| 88 | |
| 82 | |
| 68 | |
| 64 |