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
Anonymous
Not applicable

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
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

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)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

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


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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

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)

?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

...wizardry! Thank you

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 😉

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.