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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
rubentj
Frequent Visitor

Lookup value based on start and end date conditions from another table

Hi. I want to calculate a column if an instance is true. 

 

I have two tables. Table one where I have a date for each date a car is at a location.

 

 

CAR ID

Location

Date

1

A

1/1/2020

1

A

2/1/2020

1

A

3/1/2020

1

A

4/1/2020

2

B

10/1/2020

2

B

11/1/2020

2

B

12/1/2020

3

B

10/2/2020

3

B

11/2/2020

3

B

12/2/2020

 

This shows that Car 1 has been on location A between 1/1/2020 and 4/1/2020, and so on.

 

Further I have a table showing the usage of these cars per rental agreements. 

 

Car ID

Start date

End date

1

1/1/2020

3/1/2020

2

10/1/2020

10/1/2020

2

11/1/2020

11/1/2020

3

10/2/2020

11/2/2020

 

Expected result:

CAR ID

Location

Date

Is used (1 = Yes / 0 = No

1

A

1/1/2020

1

1

A

2/1/2020

1

1

A

3/1/2020

1

1

A

4/1/2020

0

2

B

10/1/2020

1

2

B

11/1/2020

1

2

B

12/1/2020

0

3

B

10/2/2020

1

3

B

11/2/2020

1

3

B

12/2/2020

0

 

So basically what I want is to calculate the column "Is Used" in Table 1 based on if the Date in Table 1 is between Start and End date in table 2 for some rows with Car ID matching. 

 

Anyone?

 

In advance, thank you so much. 

 

Best regards, 

Ruben

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1664391071035.png

 

 

Is used CC =
IF (
    COUNTROWS (
        FILTER (
            Agreement,
            Agreement[Car ID] = Location[CAR ID]
                && Agreement[Start date] <= Location[Date]
                && Agreement[End date] >= Location[Date]
        )
    ) = 0,
    0,
    1
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

A proper model facilitate possible analyses and calculations.

CNENFRNL_0-1664408310428.png

CNENFRNL_1-1664408377117.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1664391071035.png

 

 

Is used CC =
IF (
    COUNTROWS (
        FILTER (
            Agreement,
            Agreement[Car ID] = Location[CAR ID]
                && Agreement[Start date] <= Location[Date]
                && Agreement[End date] >= Location[Date]
        )
    ) = 0,
    0,
    1
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Thank you so much!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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