Forum Discussion

Henk50's avatar
Henk50
Regular Visitor
4 years ago
Solved

Checking if date falls between 2 dates on different table

Hi all,

 

I've found similar topics, but it's hard to applicate this on my case;

I have two tables:


Table Contracts

Supplier       Contract version       Contract start date           Contract end date     
A11-1-202231-1-2022
A21-3-20221-4-2022
B11-1-202231-12-2022

 

Table Invoices

Supplier       Invoice date      Calculated column; contracted supplier?         
A10-1-2022Yes
A10-2-2022No
Betcetc


The calculated column; contracted supplier is the goal.

An invoice should be registered under contract, if the invoice date falls between the begin& start date of any contract of that supplier. so in above example; In the first row of the invoice table, the invoice date is 10-1-2022. 10-1-2022 is for supplier A, a date between a contract start and enddate. 10-2-2022 isn't.


With my little dax knowledge i know that i have to search the invoice date in the contractstable, whilst keeping the filter on the supplier of that invoice. But my head can't translate this into dax yet. Any ideas?

  • Hi,

    Calculated Column in Invoices table:

    Contracted Supplier = 
    VAR InvoiceDate = Invoices[Invoice date]
    VAR Supplier = Invoices[Supplier]
    RETURN
        IF(
            COUNTROWS(
                FILTER(
                    Contracts,
                    Contracts[Supplier] = Supplier
                        && Contracts[Contract start date] <= InvoiceDate
                        && Contracts[Contract end date] >= InvoiceDate
                )
            ),
            "Yes",
            "No"
        )

    Regards

2 Replies

  • Hi,

    Calculated Column in Invoices table:

    Contracted Supplier = 
    VAR InvoiceDate = Invoices[Invoice date]
    VAR Supplier = Invoices[Supplier]
    RETURN
        IF(
            COUNTROWS(
                FILTER(
                    Contracts,
                    Contracts[Supplier] = Supplier
                        && Contracts[Contract start date] <= InvoiceDate
                        && Contracts[Contract end date] >= InvoiceDate
                )
            ),
            "Yes",
            "No"
        )

    Regards

  • Henk50's avatar
    Henk50
    Regular Visitor

    Thank you! this works and i can follow the calculations!