MIN or MAX of a Cumulative Total

Hi All,

I have searched the forum for an answer to this question however sadly cannot find so hoping to get an explanation here.

I am trying to find a way to show the MIN value of a cumulative total measure I have created for any given timeframe. The issue I am having is that I can’t use MIN or MINX etc. on the created measure in a way that works for what I need.

The Data Model consists of a fact table containing financial actuals for a given month in a “Value” column by “Period”, “Line Item”, “Currency” and dimension tables for Currency, Date, and Groupings which consolidates the line items up into various categories and whether it relates to P&L actuals or Cash actuals.

My ultimate output is to show a “Peak Cash Requirement” for any given date range which will represent the lowest cumulative cash total in that timeframe. As an example, in the screenshot below it would equal $-14,283.

image

My Net Cash Measure is a sum of the financial values, filtered for the required line items that make up net cash and I have calculated the Cume Net Cash Measure as per below

Cume Net Cash = CALCULATE( [Net Cash],
FILTER( ALL( Dates ),
Dates[Date] <= MAX( Dates[Date] ) ) )

Any help would be much appreciated, thanks!

Hello, @Ironbubble . Welcome to the Forum

I have done the same thing in one of my reports to show MIN and MAX. Below is the DAX code for MINX

MIN Net Cash =

VAR GetAllCash = ALLSELECTED(‘TABLE’[Net Cash])

VAR GetMinValue= MINX(GetAllCash,
CALCULATE(SUM(‘TABLE’[Net Cash])))

RETURN

IF(SUM(‘TABLE’[Net Cash]) = GetMinValue, GetMinValue, Blank())

For the Cumulative try:

Cumulative =

CALCULATE( [Net Cash],

FILTER( ALLSELECTED( 'Date'[Date] ),

    'Date'[Date] <= MAX('Date'[Date]) ) )

You want ALLSELECTED instead of ALL

Grant it that the names will vary according to your data names, but this will get you in the right direction.

Let me know if this works or if this is what you were looking for.

All the best,

Paul

Hi Paul,

Thank you for responding so quickly!

It may be that I am not fully understanding your response but I don’t think this will work for me since [Net Cash] is not a column in a table but a measure I created so when I start to write “ALLSELECTED(” for the first variable I can’t reference Net Cash. Unfortunately as the model contains sensitive data, I can’t share here so I will try to explain my steps in more detail:

Here is a snapshot of my fact table called “Financials”:

And of my groupings dimension table called “Groupings”:

I also have a dates table called “Dates” that I very handedly got from EnterpriseDNA.

Measures created to get to where I am currently:

  1. Total = CALCULATE(SUM(Financials[Value]),FILTER(Financials,Financials[Version] = “Latest Forecast”))

  2. Net Cash = CALCULATE( [Total], FILTER(Groupings,Groupings[Statement] = “Cash Flow”))

  3. (Previously shared) Cume Net Cash = CALCULATE( [Net Cash],
    FILTER( ALL( Dates ),
    Dates[Date] <= MAX( Dates[Date] ) ) )

I need to be able to calculate the MIN of 3) for any given date range

Regarding the Cume Net Cash Measure, I think what I have works for the purposes I need since it needs to be cumulative from the first point in time. It is only the end point that changes based on those filters (i.e. it is cumulative ITD)

Thanks again and apologies if I am missing the obvious here!

Michael

Hi Paul/Everyone,

Following on from my post above, I have spent some more time trying to work this out, sadly to no avail. In order to make things easier to look at, I have created a dummy file with random data that replicates the data model I have created. It won’t make much sense from a financials point of view but it does highlight the issue I am having.

I need to be able to callout the below value in yellow which is the lowest cumulative net cash value in this particular slate year, so represents our “peak cash requirement”

image

Similarly, I need to be able to show this for Y2, Y3 etc based on the cumulative CF for ALL years prior.

You can see the measures I have created to calculate both Net Cash and Cumulative Net Cash which seem to work as needed. The issue is that I can’t find a way to calculate the MIN of this cumulative CF measure. As far as I can tell, I can only calculate the MIN if it appears as a column in a table (virtual or otherwise) rather than a measure.

I did try and create a virtual table which I have managed to get to show Net Cash by month however I can’t then find a way to show the cumulative total of this Net Cash as a separate column, which I could then apply MINX to.

Attaching the file and any additional help would be much appreciated. It is driving me mad!

Reporting Pack - Sample Data.pbix (842.8 KB)

1 Like

Hello @Ironbubble,

Thank You for posting your query onto the Forum.

In order to achieve the results based on the scenario that you’ve mentioned. Below is the DAX measure alongwith the screenshot of the final results provided for the reference -

Peak Cash Req. - Harsh =
VAR _Cumulative_Values =
[Cume Net Cash]

VAR _Lowest_Cumulative_Value =
CALCULATE(    
    MINX(
        FILTER( Dates ,
            Dates[Date] >= MIN( Dates[Date] ) ) ,
        [Cume Net Cash] ) ,
    ALLSELECTED( Dates ) )

VAR _Results =
SWITCH( TRUE() ,
    ISINSCOPE( Dates[Month & Year] ) && [Cume Net Cash] = _Lowest_Cumulative_Value , _Lowest_Cumulative_Value ,
    NOT ISINSCOPE( Dates[Month & Year] ) , _Lowest_Cumulative_Value ,
    BLANK() )

RETURN
_Results

I’m also attaching the working of the PBIX file for the reference purposes.

Hoping you find this useful and meets your requirements that you’ve been looking for.

Thanks and Warm Regards,
Harsh

Peak Cash Requirements - Harsh.pbix (841.3 KB)

3 Likes

Hi Harsh - thank you so much, it works exactly as I was looking for it to!

I won’t pretend I understand all the steps above so will go away and work through but the main thing is the outcome answers my query in full :smile:

Hello @Ironbubble,

You’re Welcome!!!

I’m happy to see you excited with the above solution and as forum members we’re glad that we were able to assist you with your query.

Thanks and Warm Regards,
Harsh