Forum Discussion

MR2001's avatar
MR2001
Icon for Helper II rankHelper II
10 years ago
Solved

Reference a measure in another measure

Hello,

 

Is it possible to reference a measure in another measure? If yes, then can you please provide an example?

 

Thank you,

M.R.

  • Anonymous's avatar
    Anonymous
    10 years ago

    I just realized I made a mistake in my code. That code for Last Entry will return the date of the last entry, not the last entry itself. Looking back at your original formula I think it should be

     

    Last Entry = CALCULATE(
    	LASTNONBLANK( 'Trends'[Total Unresolved], 1),
    	DATESMTD(DateTable[Date])
    )

    ...or whatever the column is with the number you're trying to tally. Not the timestamp column.

     

    Now, if you really really want to have that last date with an entry, add a third measure:

     

    Last Date = CALCULATE(
    	MAX('Santiago Trends'[action_timestamp]),
    	DATESMTD(DateTable[Date])
    )

    You could use my original mistake version of Last Entry, but this version also works, and is slightly easier to type.

29 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    MR2001 Yes. This is done a lot when calculating percentages. There are numerous examples, but this post has an example given by Sean

    • MR2001's avatar
      MR2001
      Icon for Helper II rankHelper II

      What I need to do is this: I have a running total (measure) that needs to be based only on the last value in a month:

       

      Total =
      CALCULATE (
      SUM ( 'Trends'[Total Unresolved] ),
      FILTER (
      ALL ('Trends'[timestamp] ),
      'Trends'[timestamp] <= MAX ( 'Trends'[timestamp] )
      )
      )

       

      I don't want to sum all values but only the last one in a month. I can create another measure using CLOSINGBALANCEMONTH function but how can I reference it in the measure above?

       

      Filtered Total = CLOSINGBALANCEMONTH(MAX('Trends'[Total Unresolved]),'Trends'[timestamp])

       

      I tried this but it returns an error because SUM expects a column:

       

      Total =
      CALCULATE (
      SUM ([Filtered Total] ),
      FILTER (
      ALL ('Trends'[timestamp] ),
      'Trends'[timestamp] <= MAX ( 'Trends'[timestamp] )
      )
      )

       

       

      Thanks,

      M.R.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Just remove the SUM.

         

        Total = CALCULATE (
        [Filtered Total],
        FILTER (
        ALL ('Trends'[timestamp] ),
        'Trends'[timestamp] <= MAX ( 'Trends'[timestamp] )
        )
        )