When to use lastValue instead of rank


I’m trying to figure out the use case for the firstValue or lastValue function. So far what I’m finding is that it’s easier to use the rank function to do the same thing. Is there a particular use case where the firstValue or lastValue function is better than the rank function?

Let’s say for example I want to find the last status for each id in the dataset below.
lastValue versus rank

If I use lastValue on the status field, I have to add all the fields to my visual in order to not get an error.
last status value = lastValue(status, [date ASC], [id])

I can hide the columns I don’t want but I still have duplicate rows for id = 1.

To remove the duplicate, I use lastValue to find the last date and then filter to only include the last date.
last date = lastValue(date, [date ASC], [id])
last date flag = ifelse({last date} = min(date), 1, 0)
lastValue versus rank 3

This seems like a very convoluted way to get to the result I want. I can get to the same result in fewer steps using the rank function.

rank = rank([date DESC], [id])

Filter by rank = 1 to remove the duplicate rows for id = 1 and hide the columns I don’t want.

One thing I can see is if you want to do comparisons on the lastValue / firstValue

For instance if you want to do an ifelse statement to see if today a week more than the date of the lastValue then it makes sense to do it in a calculated field with lastValue.

Just one thought I had.

Yeah, I can see that being useful for some people. I can’t think of any other use case.