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