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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Steven_Phillips
Regular Visitor

Compare Date in one table to multiple rows in another table

I have what I thought would be an easy comparison but I just have gotten stuck for some reason.... I have 2 tables, a "Work Orders" table and an "Agreements" table..... I'm needing to compare whether the account that the work order is on had an agreement at the time that the work order was completed.


Work Order Table
WO CompletionWO#Acct #Had Agreement?
1/12/2022100100No
8/1/2023103100Yes
6/8/2023101200Yes
7/1/2023102300Yes
4/1/2024104300No
8/1/2024105300Yes

 

Agreement Table
Agreement NumberAgreement Start DateAgreement End DateAcct #
10007/1/20226/30/2023100
1000-17/1/20236/30/2024100
1000-27/1/20246/30/2025100
20003/1/20232/29/2024200
2000-13/1/20242/28/2025200
30001/1/202312/31/2023300
30016/1/20245/31/2025300

 

The field in blue is pretty much what I'm trying to get. I essentially just need it to look at the date on the first table and compare it to the second table to determine if the completion date falls between the agreement start and end date based on the acct #.  You'll notice with account number 300, there was a gap where they did not have agreement from 01/01/2024 through 05/31/2024 so I need to be able to account for that.

1 ACCEPTED SOLUTION
mickey64
Super User
Super User

Step 0: I use your DATA below.

mickey64_0-1721021851688.png

mickey64_2-1721021901583.png

 

Step 1: I unpivot the 'Agreement' table on Power Query Editor.

- Before -

mickey64_6-1721023416703.png

- After -

mickey64_8-1721023516034.png

 

Step 2: I add a 'Agreement Flag' column to the 'Agreement' table on Power Query Editor.

mickey64_9-1721023854007.png

 

Step 3: I add a Conditional Column named 'Date Cal' to the 'Agreement' table on Power Query Editor.

mickey64_4-1721022419184.png

 

Step 4: I make 2 tables and add some relationships on Power BI Desktop. (Date:yyyy/mm/dd)

    Calendar = CALENDAR("2020/1/1","2030/12/31")

    Acct No = SUMMARIZE('Agreement','Agreement'[Acct #])

mickey64_3-1721022303484.png

 

Step 5: I make 2 measures below.

    M_Agreement Flag = CALCULATE(SUM(Agreement[Agreement Flag]),

        FILTER(ALLSELECTED('Calendar'[Date]),'Calendar'[Date]<=MAX('Calendar'[Date])))

    M_Flag = IF('Agreement'[M_Agreement Flag]>0,"Yes","No")

 

Step 6: I add 2 columns to the 'Work Order' table on Power BI Desktop. 

    Agreement Flag = CALCULATE([M_Agreement Flag],

        KEEPFILTERS(ALLEXCEPT('Work Order','Work Order'[WO Completion],'Work Order'[Acct #])))

    Agreement Flag2 = CALCULATE([M_Flag],

        KEEPFILTERS(ALLEXCEPT('Work Order','Work Order'[WO Completion],'Work Order'[Acct #])))

mickey64_5-1721022915002.png

 

View solution in original post

1 REPLY 1
mickey64
Super User
Super User

Step 0: I use your DATA below.

mickey64_0-1721021851688.png

mickey64_2-1721021901583.png

 

Step 1: I unpivot the 'Agreement' table on Power Query Editor.

- Before -

mickey64_6-1721023416703.png

- After -

mickey64_8-1721023516034.png

 

Step 2: I add a 'Agreement Flag' column to the 'Agreement' table on Power Query Editor.

mickey64_9-1721023854007.png

 

Step 3: I add a Conditional Column named 'Date Cal' to the 'Agreement' table on Power Query Editor.

mickey64_4-1721022419184.png

 

Step 4: I make 2 tables and add some relationships on Power BI Desktop. (Date:yyyy/mm/dd)

    Calendar = CALENDAR("2020/1/1","2030/12/31")

    Acct No = SUMMARIZE('Agreement','Agreement'[Acct #])

mickey64_3-1721022303484.png

 

Step 5: I make 2 measures below.

    M_Agreement Flag = CALCULATE(SUM(Agreement[Agreement Flag]),

        FILTER(ALLSELECTED('Calendar'[Date]),'Calendar'[Date]<=MAX('Calendar'[Date])))

    M_Flag = IF('Agreement'[M_Agreement Flag]>0,"Yes","No")

 

Step 6: I add 2 columns to the 'Work Order' table on Power BI Desktop. 

    Agreement Flag = CALCULATE([M_Agreement Flag],

        KEEPFILTERS(ALLEXCEPT('Work Order','Work Order'[WO Completion],'Work Order'[Acct #])))

    Agreement Flag2 = CALCULATE([M_Flag],

        KEEPFILTERS(ALLEXCEPT('Work Order','Work Order'[WO Completion],'Work Order'[Acct #])))

mickey64_5-1721022915002.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.