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
deepblue_m45
Frequent Visitor

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!

 

deepblue_m45_0-1655405688055.png

 

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

 

1 ACCEPTED SOLUTION
Whitewater100
Solution Sage
Solution Sage

Hi:

Please see attached file. I added a date table to help it along and did some minor transformations to get the data in order. If your data went thru today, the measures could be slighly different. I hope this helps!

https://drive.google.com/file/d/1Yo8mMLjgKW1grfYdZAUShjmyuWLlyS05/view?usp=sharing 

 

Whitewater100_0-1655413142425.png

 

View solution in original post

4 REPLIES 4
Whitewater100
Solution Sage
Solution Sage

Hi:

Please see attached file. I added a date table to help it along and did some minor transformations to get the data in order. If your data went thru today, the measures could be slighly different. I hope this helps!

https://drive.google.com/file/d/1Yo8mMLjgKW1grfYdZAUShjmyuWLlyS05/view?usp=sharing 

 

Whitewater100_0-1655413142425.png

 

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
Super User
Super User

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 )
    )

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)?

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.

Top Solution Authors