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

Look Up String Value based on Transaction Date between Dates of Table

How would you write a DAX formula for a new measure that would lookup a string value from another table that contains employee position information and a start/stop date of that position.

 

Bob - Date: 2/15/2020  (that date will fluctuate because the transactional data table is formatted on a daily basis, and would be between the start/end date in the employee position table)

What is his position:  Should be Retail Associate

 

Employee Position Information

EmployeePositionStart DateEnd Date
BobTraining Associate11/1/20191/7/2020
BobRetail Associate1/8/20206/15/2020
BobRetail Manager6/16/202012/31/2050

 

 

Expected outcome

EmployeeTransaction DateSalesExpected Outcome
Bob1/4/20203Training Associate
Bob2/15/20204Retail Associate
Bob3/16/20202Retail Associate
1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@Anonymous, try this solution:

 

1. Create a star schema data model:

 

DataInsights_0-1601422172035.png

 

2. Create measure:

 

Position = 
VAR vEmp = 
    MAX ( Employee[Emp ID] )
VAR vDate = 
    MAX ( EmployeeTransaction[Date] )
VAR vEmpTable =
    FILTER (
        ALL ( EmployeePosition ),
        EmployeePosition[Emp ID] = vEmp
            && vDate >= EmployeePosition[Start Date]
            && vDate <= EmployeePosition[End Date]
    )
VAR vPosition =
    MAXX ( vEmpTable, EmployeePosition[Position] )
RETURN
    vPosition

 

3. Result:

 

DataInsights_1-1601422186237.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

1 REPLY 1
DataInsights
Super User
Super User

@Anonymous, try this solution:

 

1. Create a star schema data model:

 

DataInsights_0-1601422172035.png

 

2. Create measure:

 

Position = 
VAR vEmp = 
    MAX ( Employee[Emp ID] )
VAR vDate = 
    MAX ( EmployeeTransaction[Date] )
VAR vEmpTable =
    FILTER (
        ALL ( EmployeePosition ),
        EmployeePosition[Emp ID] = vEmp
            && vDate >= EmployeePosition[Start Date]
            && vDate <= EmployeePosition[End Date]
    )
VAR vPosition =
    MAXX ( vEmpTable, EmployeePosition[Position] )
RETURN
    vPosition

 

3. Result:

 

DataInsights_1-1601422186237.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.