Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Last date previous month not working

Hi, I have data table with date column ,for some values I have data for 30-dec and for some 31-dec however  I want to show data for latest date of that selected month in my case if I filter month year as jan 21 and area as south as per my data I dont have any data on 31dec for south so it should give me data on 30 dec BUT  it is not working .attatching picture of my data and measure for better understanding 
Hope somebody can help me. Thanks.

11 Replies

  • PREVIOUSMONTH is returning all the dates from the previous month in the current filter context, so LASTDATE will always return the final day of the month.

    You could try

    Last date previous = CALCULATE( LASTDATE(Category[Date]), PREVIOUSMONTH('Date'[Date]))

    or if you have a measure which will only return results when there is an entry for a given date

    Last date previous = LASTNONBLANK(Category[Date], [My measure])
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for your reply johnt75  it is not working in my case still giving me 31st dec

      • johnt75's avatar
        johnt75
        Icon for Super User rankSuper User

        Do you have a relationship from your Date table to Category[Date] ? If not you could try

        Last date previous = CALCULATE( LASTDATE(Category[Date]),
        TREATAS( PREVIOUSMONTH('Date'[Date]), Category[Date])
        )
  • Anonymous's avatar
    Anonymous
    Not applicable

    Not working ..

    ..

    • johnt75's avatar
      johnt75
      Icon for Super User rankSuper User

      This may be a silly question, but are you sure that the Area slicer is affecting the card visual ?

      • Anonymous's avatar
        Anonymous
        Not applicable

        Yes it is affecting ,I have selected different value in area now

         


  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    PREVIOUSMONTH(<Dates>) will return the all the dates in last month regardless of whether the date is not listed in your column.

     

    Please try LASTDATE( DATEADD( Category[Date] ).

     

    PREVIOUSMONTH(<Dates>)

    DATEADD function (DAX) - DAX | Microsoft Docs

     

    Best Regards

    Community Support Team _ chenwu zhu

     

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