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 using date range

I know this has been covered a bunch of times. But I can't seem to understand exactly how to set it up. Essentially I have an expense report, and I want to do a look up by employee number to see what budget group they are in. ( see attached SS's)  But at the same time I have to use the date range to verify that the expense is being charged to the right budget group. Currently there is only one employee that has changed budget groups, highlighted in the SS's below. Thank you for the helpE16.jpgE18.jpg

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

My error forget to change all the names that I used in my example this should do the trick:

 

Job title =
CALCULATE (
    FIRSTNONBLANK ( 'Employee Dynamic'[Job Title]; 1 );
    FILTER (
        ALL (  'Employee Dynamic' );
         'Employee Dynamic'[EmployeNumber] = 'Travel 2019'[Employee]
            && 'Employee Dynamic'[Date Start] <= 'Travel 2019'[Date]
            && 'Employee Dynamic'[Date End] >= 'Travel 2019'[Date]
    )
)


Budget Group = 
CALCULATE (
    FIRSTNONBLANK ( 'Employee Dynamic'[Budget Group]; 1 );
    FILTER (
        ALL (  'Employee Dynamic' );
         'Employee Dynamic'[EmployeNumber] = 'Travel 2019'[Employee]
            && 'Employee Dynamic'[Date Start] <= 'Travel 2019'[Date]
            && 'Employee Dynamic'[Date End] >= 'Travel 2019'[Date]
    )
)

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

12 REPLIES 12
Anonymous
Not applicable

Bump, I know it seems like such a simple solution, I just can't figure it out

Sorry I am just seeing this. I would have gotten back sooner if I had seen it. I don't know how simple it is since your date column in the Expense Table wont match the start or end date in the Employee Table. 

I am not sure if this will work, but this is my first guess (you will have to adjust the table names. I just guessed on that part).

Budget Group LookUp = 
CALCULATE(
    LOOKUPVALUE(
        'EmployeeTable'[Budget Group],
        'EmployeeTable'[EmployeeNumber],
        'ExpenseTable'[Employee Number]
    ),
    DATESBETWEEN(
        'ExpenseTable'[Date],
        'EmployeeTable'[Date Start],
        'EmployeeTable'[Date End]
    )
)
Job Title LookUp = 
CALCULATE(
    LOOKUPVALUE(
        'EmployeeTable'[Job Title],
        'EmployeeTable'[EmployeeNumber],
        'ExpenseTable'[Employee Number]
    ),
    DATESBETWEEN(
        'ExpenseTable'[Date],
        'EmployeeTable'[Date Start],
        'EmployeeTable'[Date End]
    )
)

 

Anonymous
Not applicable

@jtownsend21 

No worries. I did something similar to this but couldnt figure it out. I just replicated yours and it gave me an error shown here. Thanks JtownE21.JPG

I was afraid that would happen. Basically it's a many to many relatinoship and it can't figure out what to do. 

Try this. 

IF(
    DATESBETWEEN(
        'ExpenseTable'[Date],
        'EmployeeTable'[Date Start],
        'EmployeeTable'[Date End]
    ),
    CALCULATE(
        LOOKUPVALUE(
            'EmployeeTable'[Job Title],
            'EmployeeTable'[EmployeeNumber],
            'ExpenseTable'[Employee Number]
        )
    )
)
Anonymous
Not applicable

@jtownsend21 

Why are date start and date end greyed out? Is it because it's the whole column instead of a set date? Same with employee number in the travel sheet.

 

It keeps giving me errors Smiley Sad

 

-MichaelE22.JPG

Yes, that is correct. I wasn't thinking about that. It needs some agregation, but  you can't use one. So that solution wont work. 

 

THe other solution is closer. I think you will need to use a filter expression, but not sure. I am actually heading out for the day, so you will have to post it to the forum, or I can take a look again on Monday. 

Anonymous
Not applicable

Don't worry about it Jtown I'm going to be out all next week. Going to California for vacation. (Much needed) While I will still work on it for the rest of the day, once it's over I am getting out of here!

 

-Michael

Hi @Anonymous ,

 

Try adding the following two columns:

 

Job title =
CALCULATE (
    FIRSTNONBLANK ( 'Employee Dynamic'[Job Title]; 1 );
    FILTER (
        ALL ( Budget );
        Budget[EmployeNumber] = 'Travel 2019'[Employee]
            && 'Employee Dynamic'[Date Start] <= 'Travel 2019'[Date]
            && 'Employee Dynamic'[Date End] >= 'Travel 2019'[Date]
    )
)


Budget Group = 
CALCULATE (
    FIRSTNONBLANK ( 'Employee Dynamic'[Budget Group]; 1 );
    FILTER (
        ALL ( Budget );
        Budget[EmployeNumber] = 'Travel 2019'[Employee]
            && 'Employee Dynamic'[Date Start] <= 'Travel 2019'[Date]
            && 'Employee Dynamic'[Date End] >= 'Travel 2019'[Date]
    )
)

Believe the naming of columns is correct should work as expected.

 

Regards,

MFelix

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelix 

I can understand most of the DAX (Even though I suck at formulating it myself) but I dont Really understand the circled part in this SS. It did return all errors for this one too unfortunately.

E24.JPG

-Michael

Hi @Anonymous ,

 

My error forget to change all the names that I used in my example this should do the trick:

 

Job title =
CALCULATE (
    FIRSTNONBLANK ( 'Employee Dynamic'[Job Title]; 1 );
    FILTER (
        ALL (  'Employee Dynamic' );
         'Employee Dynamic'[EmployeNumber] = 'Travel 2019'[Employee]
            && 'Employee Dynamic'[Date Start] <= 'Travel 2019'[Date]
            && 'Employee Dynamic'[Date End] >= 'Travel 2019'[Date]
    )
)


Budget Group = 
CALCULATE (
    FIRSTNONBLANK ( 'Employee Dynamic'[Budget Group]; 1 );
    FILTER (
        ALL (  'Employee Dynamic' );
         'Employee Dynamic'[EmployeNumber] = 'Travel 2019'[Employee]
            && 'Employee Dynamic'[Date Start] <= 'Travel 2019'[Date]
            && 'Employee Dynamic'[Date End] >= 'Travel 2019'[Date]
    )
)

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Yes, I still get an error and I'm not really sure why. Let me post some SS'sE25.JPG

The 'Employee Dynamic'[Date Start] and 'Employee Dynamic'[Date End]. This is similar to Jtown's solution. 

This has been my WHOLE day lol

 

Hi @Anonymous ,

 

In this case you problem is the dot comma syntax ";" replace it by comma "," it's a question of regional settings should work as expected.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.