Forum Discussion

Dawson16's avatar
Dawson16
Frequent Visitor
4 years ago
Solved

If Statement Comparing Dates Between Tables

Hello, I am having trouble finding any information on a problem I'm having. I have a couple tables which are related by common ID numbers. The first table contains project information, which is highe...
  • v-yanjiang-msft's avatar
    4 years ago

    Hi Dawson16 ,

    According to your description, here's my solution.

    The two tables are related with the ID# column. Then create two calculated columns in the Work Orders table.

    Start Date in Project Range? =
    IF (
        'Work Orders'[Start Date] >= RELATED ( 'Projects'[Start Date] )
            && 'Work Orders'[Start Date] <= RELATED ( Projects[Finish Date] ),
        "In Range",
        "Out of Range"
    )
    
    Finish Date in Project Range? =
    IF (
        'Work Orders'[Finish Date] >= RELATED ( 'Projects'[Start Date] )
            && 'Work Orders'[Finish Date] <= RELATED ( Projects[Finish Date] ),
        "In Range",
        "Out of Range"
    )
    

    Create two calculated columns in the Projects table.

    ALL WO Start Dates in Range? =
    IF (
        COUNTROWS (
            FILTER (
                'Work Orders',
                'Work Orders'[ID #] = EARLIER ( 'Projects'[ID #] )
                    && 'Work Orders'[Start Date in Project Range?] = "Out of Range"
            )
        ) > 0,
        "No",
        "Yes"
    )
    
    ALL WO Finish Dates in Range? =
    IF (
        COUNTROWS (
            FILTER (
                'Work Orders',
                'Work Orders'[ID #] = EARLIER ( 'Projects'[ID #] )
                    && 'Work Orders'[Finish Date in Project Range?] = "Out of Range"
            )
        ) > 0,
        "No",
        "Yes"
    )
    

    Get the correct result.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.