Forum Discussion
LOOKUPVALUE within a range
- 4 years ago
evebarratt you can write a measure like this
Measure = VAR _date = MAX ( 'Table 2'[Date] ) VAR _date2 = _date - TIME ( 0, 0, 2 ) VAR _date3 = _date + TIME ( 0, 0, 2 ) VAR _date4 = _date - TIME ( 0, 0, 1 ) VAR _date5 = _date + TIME ( 0, 0, 1 ) VAR _return1 = CALCULATE ( MAX ( 'Table 1'[Created By] ), TREATAS ( CROSSJOIN ( VALUES ( 'Table 2'[ID] ), { _date } ), 'Table 1'[ID], 'Table 1'[Date] ) ) VAR _return2 = CALCULATE ( MAX ( 'Table 1'[Created By] ), TREATAS ( CROSSJOIN ( VALUES ( 'Table 2'[ID] ), { _date2 } ), 'Table 1'[ID], 'Table 1'[Date] ) ) VAR _return3 = CALCULATE ( MAX ( 'Table 1'[Created By] ), TREATAS ( CROSSJOIN ( VALUES ( 'Table 2'[ID] ), { _date3 } ), 'Table 1'[ID], 'Table 1'[Date] ) ) VAR _return4 = CALCULATE ( MAX ( 'Table 1'[Created By] ), TREATAS ( CROSSJOIN ( VALUES ( 'Table 2'[ID] ), { _date4 } ), 'Table 1'[ID], 'Table 1'[Date] ) ) VAR _return5 = CALCULATE ( MAX ( 'Table 1'[Created By] ), TREATAS ( CROSSJOIN ( VALUES ( 'Table 2'[ID] ), { _date5 } ), 'Table 1'[ID], 'Table 1'[Date] ) ) VAR _x = MAX ( MAX ( MAX ( MAX ( _return1, _return2 ), _return3 ), _return4 ), _return5 ) RETURN _x
evebarratt you should split your date/time column to date and time in the power query and then it should work. Although it is also a best practice to split these into two columns.
✨ Follow us on LinkedIn
Learn about conditional formatting at Microsoft Reactor
My latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡ Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
parry2k but if i split into date and time, Vlookup for 'Created By' won't work as ID is not unique key? Is there any way i can use range filter with Vlookup so the name is picked up if ID matches and date/time is within 2 seconds difference? Thanks.