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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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)



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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)


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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

 



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.