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 with if condition

I would like to use lookup with if condition, but there are some duplicates value in the user table. If two UserID are assigned to that ID, use the one who was assigned for the most days.

User Table 

UserIDIDStartDateEndDate
A131-03-200524-05-2005
B231-03-200519-04-2005
C309-08-200519-09-2005
E127-01-200621-04-2006
F221-02-200601-06-2006
G321-02-2006 
D413-09-2005 

 

ID Table;

IDExpected UserID
1E
2F
3G
4D

 

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

try a measure

Measure = 
var _maxPeriod = CALCULATE(MAXX('User Table',DATEDIFF('User Table'[StartDate],IF(ISBLANK('User Table'[EndDate]),TODAY(),'User Table'[EndDate]),DAY)),FILTER(ALL('User Table'),'User Table'[ID]=SELECTEDVALUE('ID Table'[ID])))
RETURN
CALCULATE(FIRSTNONBLANK('User Table'[UserID],1),FILTER(ALL('User Table'),'User Table'[ID]=SELECTEDVALUE('ID Table'[ID]) && DATEDIFF('User Table'[StartDate],IF(ISBLANK('User Table'[EndDate]),TODAY(),'User Table'[EndDate]),DAY)=_maxPeriod)),

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

View solution in original post

1 REPLY 1
az38
Community Champion
Community Champion

Hi @Anonymous 

try a measure

Measure = 
var _maxPeriod = CALCULATE(MAXX('User Table',DATEDIFF('User Table'[StartDate],IF(ISBLANK('User Table'[EndDate]),TODAY(),'User Table'[EndDate]),DAY)),FILTER(ALL('User Table'),'User Table'[ID]=SELECTEDVALUE('ID Table'[ID])))
RETURN
CALCULATE(FIRSTNONBLANK('User Table'[UserID],1),FILTER(ALL('User Table'),'User Table'[ID]=SELECTEDVALUE('ID Table'[ID]) && DATEDIFF('User Table'[StartDate],IF(ISBLANK('User Table'[EndDate]),TODAY(),'User Table'[EndDate]),DAY)=_maxPeriod)),

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