Forum Discussion

deepblue_m45's avatar
deepblue_m45
Frequent Visitor
4 years ago
Solved

Calculate Sum for Max Date -1

I have a variety of visuals showing trends over various periods and want to create a measure to place in a card visual that will calculate the max date in the visual which I have, below (h/t to AlB for the guidance here), as well as max date minus 1 month. 

 

So for instance, I have the below code that will show me 2,160 for May 2022, and I'd like a 2nd measure (hopefully in similar format to the max date if possible), that would show me 2,046 for April. I'd like to use them independently but I'd likely combine them to do a current month minus prior month. 

 

Any guidance or suggestions would be appreciated!

 

 

Max Date = 
VAR __latestdate =
MAX('Date Hierarchy'[Month Year])
RETURN
    CALCULATE(
        SUM('DataTable-2020-2022'[Value]),
        FILTER('Date Hierarchy','Date Hierarchy'[Month Year] = __latestdate)
)

 

4 Replies

    • Whitewater100's avatar
      Whitewater100
      Icon for Solution Sage rankSolution Sage

      Here is the excel if ou want to examine with the data I used.

       

      Description2021-052021-062021-072021-082021-092021-102021-112021-122022-012022-022022-032022-042022-05
      Category 12247181814051194294022632320138119651818116515541815
      Category 2545329726610426602286755906166277905489
  • tamerj1's avatar
    tamerj1
    Icon for Community Champion rankCommunity Champion

    Hi deepblue_m45 

    Please try

    Max Date =
    VAR __latestdate =
        MAXX (
            ALLSELECTED ( 'Date Hierarchy'[Month Year] ),
            'Date Hierarchy'[Month Year]
        )
    RETURN
        CALCULATE (
            SUM ( 'DataTable-2020-2022'[Value] ),
            FILTER ( 'Date Hierarchy', 'Date Hierarchy'[Month Year] = __latestdate )
        )
    • deepblue_m45's avatar
      deepblue_m45
      Frequent Visitor

      Thanks for the reply! I plugged this in and it works great for the May date. Is there a way to use this to show the month before that (the April equivalent)?