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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Need help in Lookup and Condition

I would like to use lookup with a condition, but there is some duplicates value in the ID table. There are two tables UserId table & ID table. Check id from ID table with Date & where it falls in UserId table column- StartDate, EndDate depends on that assign userid for that Id. If the End date of UserId table blank consider Today().

UserId Table 

UserIDIDStartDateEndDate
A104-09-201803-03-2019
B103-03-2019 

 

ID Table

ID Date Expected UserID
101-09-2018 
102-09-2018 
103-09-2018 
104-09-2018 
105-09-2018A
117-10-2018A
101-03-2019A
102-03-2019A
103-03-2019A
104-03-2019B
105-03-2019B
106-03-2019B
11-1-2020B

 

 

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

hi @Anonymous 

try a measure

Expected UserID =
CALCULATE(FIRSTNONBLANK('UserId Table'[UserId], 1),
FILTER(ALL('UserId Table'), 'UserId Table'[StartDate] < SELECTEDVALUE('ID Table'[Date]) && ('UserId Table'[EndDate] >= SELECTEDVALUE('ID Table'[Date]) || ISBLANK('UserId Table'[EndDate]))
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

If you have duplicates, use MAXX with a FILTER instead of LOOKUPVALUE.


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
az38
Community Champion
Community Champion

hi @Anonymous 

try a measure

Expected UserID =
CALCULATE(FIRSTNONBLANK('UserId Table'[UserId], 1),
FILTER(ALL('UserId Table'), 'UserId Table'[StartDate] < SELECTEDVALUE('ID Table'[Date]) && ('UserId Table'[EndDate] >= SELECTEDVALUE('ID Table'[Date]) || ISBLANK('UserId Table'[EndDate]))
)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors