Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Lookup in measures with context filter

Hi,

 

I would like to use to include a lookup function but with context filter, which does not seem possible with "lookupvalue".

 

Let me explain, I have a (big) table called "truckload" with a column of:

- IDs,

- timestamp (of events)

- data (when event occurs)

 

IDstimestampvalue
1B4E60A2021-09-28T09:00:0443
2B4E60B2021-09-28T09:00:0842
1B4E60A2021-09-28T09:00:264

 

When I use a slicer of time to visualize information (a selection of time between dates), I have a measure to get the lastest time event of each ID in the defined date/time window:

lastesttime = CALCULATE(MAX(truckload[timestamp]),ALLEXCEPT(truckload,truckload[ID],truckload[timestamp]))
 
It works fine:
IDlatesttime
1B4E60A2021-09-28T09:00:26
2B4E60B2021-09-28T09:00:08

 

But then I would like the "value" corresponding to this "latesttime" event in my table to have:

IDlatesttimelatestvalue
   
   

 

I tried to use lookup functions but I cannot succeed to keep the context filter of the ID.

 

For exemple, the following does not work because I have identical timestamps for the IDs and so this lookup function returns often -50 (multiple values are found, the IDs are not separated in the search):

 

latestvalue = CALCULATE (
SELECTEDVALUE ( truckload[value], -50 ),
FILTER (
ALLEXCEPT(truckload,truckload[ID] ),
truckload[timestamp] == truckload[lastesttime]
)
)

Note that I have unique timestamps for each ID.

So how can I get the value corresponding to this "latestime" using a measure?

 

Thanks!

 

Regards,

 

Renardo

 

  • Anonymous , I think you should try measure like

     

    lastesttime = CALCULATE(MAX(truckload[timestamp]),ALLEXCEPT(truckload,truckload[ID]))

     

    lastest value = CALCULATE(lastnonblankvalue(truckload[timestamp], sum(truckload[value])),ALLEXCEPT(truckload,truckload[ID]))

2 Replies

  • Anonymous , I think you should try measure like

     

    lastesttime = CALCULATE(MAX(truckload[timestamp]),ALLEXCEPT(truckload,truckload[ID]))

     

    lastest value = CALCULATE(lastnonblankvalue(truckload[timestamp], sum(truckload[value])),ALLEXCEPT(truckload,truckload[ID]))

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI,

    Thanks a lot! I was lost in the context filters and what you suggested does work.