Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Last Row Flag Most Current

Hello,

 

I am trying to flag the row that contains the last time an animal was fed using a Dax Custom Column for splicing a visual. 

 

My data is below: I would like to obtain Last Meal.

 

The column inputs a 1 for the most recent row entry and if another entry comes in, it is replaced.

 

Thanks for any help.

 

AnimalFood Units AteLast Meal
Tiger50
Tiger30
Lion50
Lion21
Tiger40
Tiger40
Elephant20
Elephant40
Elephant51
Tiger20
Tiger20
Tiger41
Monkey11
  • Oooh, compared with your last one, this one is trivial:

     

    Last Meal Column = 
    VAR __Index = [Index]
    RETURN IF(__Index=MAXX(FILTER(ALL(LastMeal),[Animal]=EARLIER([Animal])),[Index]),1,0)

    Assumes an Index column like the last solution (Cthulu).

7 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Oooh, compared with your last one, this one is trivial:

     

    Last Meal Column = 
    VAR __Index = [Index]
    RETURN IF(__Index=MAXX(FILTER(ALL(LastMeal),[Animal]=EARLIER([Animal])),[Index]),1,0)

    Assumes an Index column like the last solution (Cthulu).

    • Anonymous's avatar
      Anonymous
      Not applicable
      Last Meal Column = 
      VAR __Index = [Index]
      RETURN IF(__Index=MAXX(FILTER(ALL(Table1),[Animal]=EARLIER([Animal])),[Index]),1,0)

      Small tweak and it worked ;)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Darn, I have a caveat that I didn't see, 

       

      AnimalFood Units AteLast Meal
      Tiger50
      Tiger30
      Lion50
      Lion21
      Tiger40
      Tiger40
      Elephant20
      Elephant40
      Elephant51
      Tiger20
      Tiger20
      Tiger41
      Monkey11
      Monkey 0
      Tiger 0
      Elephant 0
      Tiger 0

       

      How my dataset is, there are blank values at the bottom that have not occured yet. I thought I could use AllExceptBlank() as a replacement to overcome this but it doesn't work. Otherwise, the last 4 rows are flagged regardless of them not being fed

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        Maybe:

         

        Last Meal Measure = 
        VAR __Index = MAX([Index])
        VAR __Animal = MAX([Animal])
        RETURN IF(__Index=MAXX(FILTER(ALL(LastMeal),[Animal]=__Animal && NOT(ISBLANK([Food Units Ate]))),[Index]),1,0)

        ?

    • Daviejoe's avatar
      Daviejoe
      Memorable Member
      Hi Greg, just spotted your link to your DAX Cookbook, just got it off that small online store Amazon, look forward to delving into it! Regards David
  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Here it is as a measure.

     

    Last Meal Measure = 
    VAR __Index = MAX([Index])
    VAR __Animal = MAX([Animal])
    RETURN IF(__Index=MAXX(FILTER(ALL(LastMeal),[Animal]=__Animal),[Index]),1,0)