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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
viewSonic123
Frequent Visitor

Daily Running Total of Latest values per Group

Hi,

I'm trying to get a daily running total of the values of 1 group. The data received is not daily and changes are only shown if the ID gets updated. I need to get a running total per day of the latest value by ID. Help would be greatly appreciated!

 

Any idea of how to keep this as a measure? I also have a slicer that allows users to choose the max date (ex. max date 1/6 would not have 1/7 data present)

 

edit: I'm trying to insert a pbix but says that it is not supported...

 

Sample data I get:

IDValueDate
111/1/2022
221/3/2022
161/4/2022
241/4/2022
321/5/2022
1151/7/2022
201/6/2022
3101/6/2022

running total: what I want

DateRunning total
1/1/20221
1/2/20221
1/3/20223
1/4/202210
1/5/202212
1/6/202216
1/7/202225
1 ACCEPTED SOLUTION

hi @viewSonic123 

you would need to 

 

1) create a Date Table with this code 

 

DateTable = CALENDAR(MIN('FactTable'[Date]), MAX('FactTable'[Date]))

 

2) connect two Date columns

3) create a measure with this code:

 

LatestSum = 
VAR CurrentDate = MAX(DateTable[Date])
RETURN
SUMX(
    ALL(FactTable[ID]),
    VAR CurrentID = FactTable[ID]
    VAR MaxDate = 
        CALCULATE( 
            MAX(FactTable[Date]), 
            FILTER(                
                ALL(FactTable),                  
                FactTable[Date] <= CurrentDate && FactTable[ID] = CurrentID            
            ) 
        )
    RETURN 
        CALCULATE(
            MAX(FactTable[Value]),
            FILTER(
                ALL(FactTable),  
                FactTable[Date] = MaxDate &&  FactTable[ID] = CurrentID
            )
        )
)

 

4) then plot with the DateTable[Date] and the measure above.

 

I tried and it worked like this:

FreemanZ_0-1670739222644.png

 

View solution in original post

11 REPLIES 11
FreemanZ
Super User
Super User

For 1/7/2022, how do you get 25?

Sorry, I accidentally changed the value for 1, 15, 1/7/2022  (correct) to 1, 8, 1/7/2022 (incorrect)

I have changed the main question with the correct data. 

1/7/22 would be 25 as the most recent for 1 = 15, 2 = 0, 3 = 10

For 1/7 ID's 1,2,3 have a most recent value of 15, 0, 10, respectively

 

Therefore the running total = 25

hi @viewSonic123 

you would need to 

 

1) create a Date Table with this code 

 

DateTable = CALENDAR(MIN('FactTable'[Date]), MAX('FactTable'[Date]))

 

2) connect two Date columns

3) create a measure with this code:

 

LatestSum = 
VAR CurrentDate = MAX(DateTable[Date])
RETURN
SUMX(
    ALL(FactTable[ID]),
    VAR CurrentID = FactTable[ID]
    VAR MaxDate = 
        CALCULATE( 
            MAX(FactTable[Date]), 
            FILTER(                
                ALL(FactTable),                  
                FactTable[Date] <= CurrentDate && FactTable[ID] = CurrentID            
            ) 
        )
    RETURN 
        CALCULATE(
            MAX(FactTable[Value]),
            FILTER(
                ALL(FactTable),  
                FactTable[Date] = MaxDate &&  FactTable[ID] = CurrentID
            )
        )
)

 

4) then plot with the DateTable[Date] and the measure above.

 

I tried and it worked like this:

FreemanZ_0-1670739222644.png

 

@FreemanZ  How would I be able to add multiple 'All Page' filters onto this measure? Is that possible?

 

Ex. I have a filter in the slicer pane and would like for the measure to filter on that filter.

I am able to get what I wanted in the above reply:

Is this what others would do? ( I added the KEEPFILTERS() function )

 

LatestSum = 
VAR CurrentDate = MAX(DateTable[Date])
RETURN
SUMX(
    ALL(FactTable[ID]),
    VAR CurrentID = FactTable[ID]
    VAR MaxDate = 
        CALCULATE( 
            MAX(FactTable[Date]), 
            FILTER(                
                ALL(FactTable),                  
                FactTable[Date] <= CurrentDate && FactTable[ID] = CurrentID            
            ) 
        )
    RETURN 
        CALCULATE(
            MAX(FactTable[Value]),
            KEEPFILTERS(
                FILTER(
                    ALL(FactTable),  
                    FactTable[Date] = MaxDate &&  FactTable[ID] = CurrentID
                )
            )
        )
)

 

 

congratulations. KEEPFILTER is suspposed to work in any filter argument of CALCULATE, no matter how complicated it is. Your scenario is already very specific and complicated, it is hard to say what others would do. 

Thank you again @FreemanZ for the response! You have helped me a great deal. Thanks!

Thank you so much FreemanZ! The measure you provided got me what I wanted! I need to get better at dax.

Thank you again!

viewSonic123
Frequent Visitor

Running totalDate
11/1/2022
11/2/2022
31/3/2022
101/4/2022
121/5/2022
161/6/2022
251/7/2022

Result expected

viewSonic123
Frequent Visitor

Date

Running Total

1/1/221
1/2/221
1/3/223
1/4/2210
1/5/2212
1/6/2216
1/7/2225

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.