Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Latest month calculation

Hi   I'm after some help with creating a "Latest month" measure which is slightly beating me.   I would like to create a card which shows a count of records based on the latest month available in...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

     

    If  the date filter is based on the current date, please try:

    Last date based on Today = 
    var _date=MAXX(FILTER('Table',[Date]<TODAY()),[Date])
    return CALCULATE(SUM('Table'[Value]),FILTER('Table',[Date]=_date)) 

     

    Or if you want a dynamic date filter, please add a calendar table firstly. For example:

    Date Filter = CALENDAR(MIN('Table'[Date]),TODAY()) 

    Then 

    Last date based on date filter = 
    var _last= MAXX(FILTER('Table',[Date]<MAX('Date Filter'[Date])),[Date])
    return CALCULATE(SUM('Table'[Value]),FILTER('Table',[Date]=_last)) 

     

     

    Or based on the previous month of date filter:

    Last month based on date filter = 
    var _last= MAXX(FILTER('Table',[Date]<MAX('Date Filter'[Date]) && YEAR([Date])*100+MONTH([Date])< YEAR(MAX('Date Filter'[Date]))*100 + MONTH(MAX('Date Filter'[Date]))),[Date])
    return CALCULATE(SUM('Table'[Value]),FILTER('Table',[Date]=_last))

     

    Best Regards,
    Eyelyn Qin
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.