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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
DJSwezey
Helper I
Helper I

Sort order breaks running total measure!!

I have a simple sales table below: 'Sales'

 

DJSwezey_6-1682969543545.png

 

This thrown into a simple Matrix looks like this:

DJSwezey_9-1682970255748.png

 

My objective is to move the TOTALs to the front of the matrix (left) and then to create a measure that results in a running total week over week of the Goal amounts. To do this I created a new table ( 'Week Order' ) to sum all data across all date points. See picture below:

 

DJSwezey_5-1682969503144.png

I then related the two tables on 'Sales'[Week] and 'Week Order'[Week Date]

 

DJSwezey_3-1682968967784.png

 

This allows me to use 'Week Order'[Week Of] as the column object in my matrix. 

 

DJSwezey_4-1682969066151.png

 

Now I need to create a measure to calculate the running total of the Goal amounts.

 

Goal Running Total = CALCULATE(
    sum(Sales[Goal]),
    FILTER(
        all('Week Order'[Week Of]),
        'Week Order'[Week Of] <= MAX('Week Order'[Week Of])
    )
)

 

When I throw this measure into the matrix everything works fine before sorting [Week Of]. You can see below that the running total for goals adds each week. 4/10/23 = 250, 4/17/23 = 100 + 250, 4/3/2023 = 125+ 100 + 250

DJSwezey_7-1682969841950.png

Now, when I sort [Week Of] by [Order] the measure no longer compiles the Goal total each week.

This is the problem I need help solving.

 

DJSwezey_8-1682970065330.png

 

 

1 REPLY 1
lbendlin
Super User
Super User

Try this version

 

Goal Running Total = 
var mx = MAX('Week Order'[Week Of])
return CALCULATE( sum(Sales[Goal]),'Week Order'[Week Of] <= mx)

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.