Forum Discussion

PaisleyPrince's avatar
PaisleyPrince
Icon for Advocate II rankAdvocate II
2 years ago
Solved

Obtaining latest value for maximum date in dax

Hi,

I'm trying to write a measure which will calculate the latest status of an item , by location and by the maximum date applicable. Sample data as per below. Any guidance would be much appreciated.

thanks

Scott

 

 

  • Greg_Deckler's avatar
    Greg_Deckler
    2 years ago

    PaisleyPrince This seems to work for me. See PBIX attached beneath signature:

    Latest Status = 
        VAR __LatestDate = MAX('Table'[Date])
        VAR __Result = MAXX(FILTER('Table',[Date] = __LatestDate), [Status])
    RETURN
        __Result

5 Replies

    • PaisleyPrince's avatar
      PaisleyPrince
      Icon for Advocate II rankAdvocate II

      Greg_Deckler , thanks for this pattern. My only question is that i'm looking up a status rather than a numerical value - can you please advise how would i amend the pattern accordingly?

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        PaisleyPrince Is largely the same. Can't test because you didn't provide your sample data in text and no idea about your visual but should be something like:

        Measure =
          VAR __Item = MAX('Table'[Item])
          VAR __Location = MAX('Table'[Location])
          VAR __Table = FILTER( ALLSELECTED('Table'), [Item] = __Item && [Location] = __Location )
          VAR __MaxDate = MAXX( __Table, [date] )
          VAR __Result = MAXX( FILTER( __Table, [date] = __MaxDate ), [Status] )
        RETURN
          __Result

         

  • Hi Greg_Deckler , I've tried it but it doesnt work as expected. For example Item 2 - S01 gives the wrong result. Sample data in text is as follows

    ItemlocationStatusDate
    1S01Current 01/02/2024
    1S02Discount01/03/2023
    1S03Notrequest22/07/2023
    1S01Discount30/11/2023
    1S02Notrequest01/07/2023
    1S03Current 18/05/2022
    2S01Current 17/02/2022
    2S02Notrequest01/12/2023
    2S03Discount01/12/2023
    2S01Discount15/06/2023
    2S02Current 22/03/2024
    2S03Notrequest22/01/2024
    3S01Discount11/02/2023
    3S02Notrequest11/02/2024
    3S03Current 11/05/2023
    3S01Current 16/05/2023
    3S02Discount12/03/2024
    3S03Discount12/02/2023
    • Greg_Deckler's avatar
      Greg_Deckler
      Icon for Community Champion rankCommunity Champion

      PaisleyPrince This seems to work for me. See PBIX attached beneath signature:

      Latest Status = 
          VAR __LatestDate = MAX('Table'[Date])
          VAR __Result = MAXX(FILTER('Table',[Date] = __LatestDate), [Status])
      RETURN
          __Result