Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Cumulative Running Total on virtual Table

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,

 

 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

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,
        {
            12 },
            24 },
            36 }
        }
    )
VAR vAddRT =
    ADDCOLUMNS (
        vTable,
        "RT",
            VAR thisrowindex = [Index]
            RETURN
                SUMX ( FILTER ( vTable, [Index] <= thisrowindex ), [Value] )
    )
RETURN
    vAddRT

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
pellow17
Regular Visitor

@mahoneypat Although you posted this three years ago, many thanks! I had been searching for this answer for hours!

mahoneypat
Microsoft Employee
Microsoft Employee

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,
        {
            12 },
            24 },
            36 }
        }
    )
VAR vAddRT =
    ADDCOLUMNS (
        vTable,
        "RT",
            VAR thisrowindex = [Index]
            RETURN
                SUMX ( FILTER ( vTable, [Index] <= thisrowindex ), [Value] )
    )
RETURN
    vAddRT

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors