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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jfox61
Frequent Visitor

Running totals showing in my graph after today

I have a graph:

jfox61_0-1679935014633.png

 

It seems like this should be so easy, maybe a filter on my graph? I have researched quite a bit and have found no easy way to do this. Can you please help?

9 REPLIES 9
Greg_Deckler
Super User
Super User

@jfox61 Add this to your measure:

RETURN

  IF( MAX('Date'[Date] > TODAY(), BLANK(), __Result)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

So I tried to create a new measure:

Before Today = RETURN IF( MAX('Registrations'[Date] <= TODAY(), BLANK(), __Result))
 
and am getting a syntax error:
The syntax for 'RETURN' is incorrect. (DAX(RETURN IF( MAX('Registrations'[Date] <= TODAY(), BLANK(), __Result)))).
 
Which I should be able to figure out but ......

Hi Greg,

Thank you and now another question, do I add this:

RETURN

  IF( MAX('Date'[Date] > TODAY(), BLANK(), __Result)

 

to my running total measure? If so where, at the end? I know this is annoying very beginner-ish!

 

Count of Unit running total in Month =
CALCULATE(
    COUNTA('Registrations'[Unit]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'Registrations',
                'Registrations'[Date].[MonthNo],
                'Registrations'[Date].[Month]
            ),
            ALLSELECTED('Registrations')
        ),
        ISONORAFTER(
            'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
            'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC
        )
    )
)

@jfox61 Yes, like this:

Count of Unit running total in Month =
VAR __Result = 
CALCULATE(
    COUNTA('Registrations'[Unit]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'Registrations',
                'Registrations'[Date].[MonthNo],
                'Registrations'[Date].[Month]
            ),
            ALLSELECTED('Registrations')
        ),
        ISONORAFTER(
            'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
            'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC
        )
    )
)
RETURN
  IF( MAX('Date'[Date] > TODAY(), BLANK(), __Result)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Oh my gosh thank you for coming back!

So I added:

Count of Unit running total in Month =
CALCULATE(
    COUNTA('Registrations'[Unit]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'Registrations',
                'Registrations'[Date].[MonthNo],
                'Registrations'[Date].[Month]
            ),
            ALLSELECTED('Registrations')
        ),
        ISONORAFTER(
            'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
            'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC

        )
    )
) RETURN
  IF(MAX('Date'[Date] > TODAY(), BLANK(),__Result)
 
Didn't work
 
So I changed the statement to 
RETURN
  IF(MAX('Date'[Month] > TODAY(), BLANK(),__Result) - at the end
 
And then finally below
Count of Unit running total in Month =
CALCULATE(
    COUNTA('Registrations'[Unit]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'Registrations',
                'Registrations'[Date].[MonthNo],
                'Registrations'[Date].[Month]
            ),
            ALLSELECTED('Registrations')
        ),
        ISONORAFTER(
            'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
            'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC

        )
    )
) RETURN
  IF(MAX('Date'[MonthNo] > TODAY(), BLANK(),__Result)
 
And I'm getting big fat syntax errors. I have tried multiple things, nothing works.
jfox61_0-1680275019965.png

 

Thank you, thank you

@jfox61 You're missing your VAR definition. To use a RETURN statement you need a VAR statement. Check the code I posted again. It's the second line of the code. If you really want to (although I highly recommend against it) you could do it without the VAR and RETURN. But you really should use VAR's because they help break up your code into manageable chunks that you can debug using things like TOCSV, etc.

 

Count of Unit running total in Month =
IF( MAX('Date'[Date] > TODAY(), BLANK(),
CALCULATE(
    COUNTA('Registrations'[Unit]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'Registrations',
                'Registrations'[Date].[MonthNo],
                'Registrations'[Date].[Month]
            ),
            ALLSELECTED('Registrations')
        ),
        ISONORAFTER(
            'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
            'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC
        )
    )
)
)

Another thing, there is far easier syntax to create a running total: Better Running Total - Microsoft Power BI Community

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

I'm really trying here, I swear. 

I tried your simpler version to no avail. I got syntax errors there too so it's something that I am doing....

 

I tried this code:

Count of Unit running total in Month =
VAR _RESULT =
CALCULATE(
COUNTA('Registrations'[Unit]),
FILTER(
CALCULATETABLE(
SUMMARIZE(
'Registrations',
'Registrations'[Date].[MonthNo],
'Registrations'[Date].[Month]
),
ALLSELECTED('Registrations')
),
ISONORAFTER(
'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC
)
)
)
RETURN IF( MAX('Date'[Date] > TODAY(), BLANK(), _RESULT))

 

in the DAX Formatter on-line, it points to the parens by Blank.. well here is a screenshot:

jfox61_0-1680292471860.png

The syntax error I get in Power BI says there are too many arguments. 

Thank you for the information sorry I didn't read your code in full! I am still getting a syntax error that says "Too many arguments were passed to the MAX function. The maximum argument count for the function is 2."

 

My Code

Count of Unit running total in Month = VAR _RESULT = CALCULATE(
    COUNTA('Registrations'[Unit]),
    FILTER(
        CALCULATETABLE(
            SUMMARIZE(
                'Registrations',
                'Registrations'[Date].[MonthNo],
                'Registrations'[Date].[Month]
            ),
            ALLSELECTED('Registrations')
        ),
        ISONORAFTER(
            'Registrations'[Date].[MonthNo], MAX('Registrations'[Date].[MonthNo]), DESC,
            'Registrations'[Date].[Month], MAX('Registrations'[Date].[Month]), DESC

        )
    )
) RETURN  IF( MAX('Date'[Date] > TODAY(), BLANK(), _RESULT))
 
I will look at the video you sent me, thank you. This code came from using the quick measure for running total.
jfox61
Frequent Visitor

This is my date setup

jfox61_0-1680275425859.png

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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