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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
neil37
Advocate I
Advocate I

Running Total - Do Not Want to See past Today's Date

Hello, 

 

I use the following code to calculate the running total of counts:

 

 

 

Count of ucr_code running total in Month =
CALCULATE(
COUNTA('lwchrg (2)'[code]),
FILTER(
CALCULATETABLE(
SUMMARIZE(
'lwmain (2)',
'lwmain (2)'[date_occu].[MonthNo],
'lwmain (2)'[date_occu].[Month]
),
ALLSELECTED('lwmain (2)')
),
ISONORAFTER(
'lwmain (2)'[date_occu].[MonthNo], MAX('lwmain (2)'[date_occu].[MonthNo]), DESC,
'lwmain (2)'[date_occu].[Month], MAX('lwmain (2)'[date_occu].[Month]), DESC

 

 

 

 

BUT - I do not want it to count past todays Date. Is there a filter or add-in code to this current measure to prevent it from counting past today?

 


I do not want the code to calculate past today's date (i.e., March, April, May, etc. of 2022.).

 

neil37_0-1645111921067.png

 

 

Thank you!

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @neil37 ,

Please have a try.

Modify the formula before.

 

Measure =
VAR result =
    CALCULATE (
        COUNTA ( 'lwchrg (2)'[code] ),
        FILTER (
            ALLSELECTED ( 'lwmain (2)' ),
            'lwmain (2)'[date_occu].[MonthNo] <= MAX ( 'lwmain (2)'[date_occu].[MonthNo] )
                && 'lwmain (2)'[date_occu].[Year] = MAX ( 'lwmain (2)'[date_occu].[Year] )
                && 'lwmain (2)'[date_occu] <= TODAY ()
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'lwmain (2)'[date_occu].[MonthNo] ) > MONTH ( TODAY () )
            && SELECTEDVALUE ( 'lwmain (2)'[date_occu].[Year] ) >= YEAR ( TODAY () ),
        BLANK (),
        result
)

 

vpollymsft_0-1645585643785.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @neil37 ,

Please have a try.

Modify the formula before.

 

Measure =
VAR result =
    CALCULATE (
        COUNTA ( 'lwchrg (2)'[code] ),
        FILTER (
            ALLSELECTED ( 'lwmain (2)' ),
            'lwmain (2)'[date_occu].[MonthNo] <= MAX ( 'lwmain (2)'[date_occu].[MonthNo] )
                && 'lwmain (2)'[date_occu].[Year] = MAX ( 'lwmain (2)'[date_occu].[Year] )
                && 'lwmain (2)'[date_occu] <= TODAY ()
        )
    )
RETURN
    IF (
        SELECTEDVALUE ( 'lwmain (2)'[date_occu].[MonthNo] ) > MONTH ( TODAY () )
            && SELECTEDVALUE ( 'lwmain (2)'[date_occu].[Year] ) >= YEAR ( TODAY () ),
        BLANK (),
        result
)

 

vpollymsft_0-1645585643785.png

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@Anonymous  Thank you!!! Greatly appreciate you're diligence, intelligence, and patience

Anonymous
Not applicable

Hi @neil37 ,

Hi @neil37 ,

I have created a simple sample,please refer to it to see if it helps you.

Create a measure.

 

Measure =
CALCULATE (
    COUNTA ( 'lwchrg (2)'[code] ),
    FILTER (
        ALLSELECTED ( 'lwmain (2)' ),
        'lwmain (2)'[date_occu].[MonthNo] <= MAX ( 'lwmain (2)'[date_occu].[MonthNo] )
            && 'lwmain (2)'[date_occu].[Year] = MAX ( 'lwmain (2)'[date_occu].[Year] )
            && 'lwmain (2)'[date_occu] <= TODAY ()
    )
)

 

 

vpollymsft_0-1645521056871.png

 

If I have misunderstood your meaning, please provide your pbix without privacy information and desired output.

 

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Hi @Anonymous , 

 

Thank you for your support and response. 

 

Unfortunately, we have gotten to the point where the running total is calculated - the only problem is we want that running total to completely stop counting for any date past Today.

 

So in your table example, we'd like the table to show a running count that does not extend past the current month:

 

Month20212022
Jan.21
Feb.32
March6 
April7 
May8 
June9 
July10 
August11 

 

In the image below, we'd like the line to stop at the current month:

 

2RunningTotalSS.jpg

 

We've tried calendar table filters to not extend past todays date and nothing seems to stop that running total from continuing to count throughout the current year. 

 

Thank you again for your help.

 

 

 

amitchandak
Super User
Super User

@neil37 , try like

 


Count of ucr_code running total in Month =
CALCULATE(
COUNTA('lwchrg (2)'[code]),
FILTER(
CALCULATETABLE(
SUMMARIZE(
'lwmain (2)',
'lwmain (2)'[date_occu].[MonthNo],
'lwmain (2)'[date_occu].[Month]
),
ALLSELECTED('lwmain (2)')
),
ISONORAFTER(
'lwmain (2)'[date_occu].[MonthNo], MAX('lwmain (2)'[date_occu].[MonthNo]), DESC,
'lwmain (2)'[date_occu].[Month], MAX('lwmain (2)'[date_occu].[Month]), DESC
), 'lwmain (2)'[date_occu] <=today()
))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak  Thank you for your quick response!

 

Unfortunately, I am getting an error that says " there are too many arguements were passed to the FILTER function. The max arguement count for the function is 2."

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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