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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Running Total based on category

With the following table 'Data', I would like to write a measure that calculates the running total based on "Product".

 

Input Table: 'Data'

ProductTypeCost
AMaterial200
AManpower150
AMachine80
BMaterial300
BManpower140
BMachine120
CMaterial240
CManpower200
CMachine10

 

Ideal Output:

ProductCostCost Running Total
B560560
C4501010
A4301440

 

My current workaround is to use the following DAX formula to create a calculated table, 'Data by Product'; connect the two tables, 'Data' and 'Data by Product' with a relationship table, 'Product' that contains only { "A", "B", "C" }, then finally use the following measure, "Cost Running Total" to calculate the running total cost based on the [Cost] column in descending order. 

 

 

Data by Product = 
SUMMARIZE(
    'Data',
    Data[Product],
    "Cost", SUM(Data[Cost])
)

 

 

 

Cost Running Total = 
    CALCULATE(
        SUM(Data[Cost]),
        FILTER(
            ALLSELECTED('Product'[Product]),
            Data[Cost] >= MIN('Data by Product'[Cost])
        )
    )

 

 

 

Any less cumbersome way to perform the same calculation? 

2 ACCEPTED SOLUTIONS
DataInsights
Super User
Super User

@Anonymous, try this:

 

1. Create a table ProductMaster. Sort the Product column by the Index column (controls the sorting in the table visual). 

 

DataInsights_0-1600280855916.png

 

2. Join ProductMaster to the data table.

 

DataInsights_1-1600280893819.png

 

3. Create measures.

 

Total Cost = SUM ( ProductCost[Cost] )

Running Total = 
VAR vSelProd =
    SELECTEDVALUE ( ProductMaster[Index] )
VAR vResult =
    CALCULATE (
        [Total Cost],
        ProductMaster[Index] <= vSelProd,
        ALL ( ProductMaster[Product] )
    )
RETURN
    vResult

 

4. Create a table visual, using ProductMaster[Product] and the measures.

 

5. Result:

 

DataInsights_2-1600280916750.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

FrankAT
Community Champion
Community Champion

Hi @Anonymous 

what about the following solution:

 

16-09-_2020_22-32-55.png

 

Sum of Cost = SUM(Data[Cost])

Running Total = 
CALCULATE(
    [Sum of Cost],
    FILTER(
        ALL(Data),
        MIN(Data[Product]) <= Data[Product]
    )
)

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

View solution in original post

2 REPLIES 2
FrankAT
Community Champion
Community Champion

Hi @Anonymous 

what about the following solution:

 

16-09-_2020_22-32-55.png

 

Sum of Cost = SUM(Data[Cost])

Running Total = 
CALCULATE(
    [Sum of Cost],
    FILTER(
        ALL(Data),
        MIN(Data[Product]) <= Data[Product]
    )
)

 

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

DataInsights
Super User
Super User

@Anonymous, try this:

 

1. Create a table ProductMaster. Sort the Product column by the Index column (controls the sorting in the table visual). 

 

DataInsights_0-1600280855916.png

 

2. Join ProductMaster to the data table.

 

DataInsights_1-1600280893819.png

 

3. Create measures.

 

Total Cost = SUM ( ProductCost[Cost] )

Running Total = 
VAR vSelProd =
    SELECTEDVALUE ( ProductMaster[Index] )
VAR vResult =
    CALCULATE (
        [Total Cost],
        ProductMaster[Index] <= vSelProd,
        ALL ( ProductMaster[Product] )
    )
RETURN
    vResult

 

4. Create a table visual, using ProductMaster[Product] and the measures.

 

5. Result:

 

DataInsights_2-1600280916750.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.