Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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)


Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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)

?



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.