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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
scott_od
Frequent Visitor

Complex comparison of two excel files

I'm looking for some help please with this scenario which is too complex for me to resolve with my power query knowledge.


Scenario

I have 2 tables:

- tabel 1 contains a list of items ordered by my customers

- table 2 cotains a list of items provided by my supplier in order to fullfill my customer's orders

The supplier is not privvy to my customer's names, so they provide information at item level, which I need to cross reference against my customer's orders to see if they can be fullfilled.

 

Sometimes I receive the correct amount of items, sometime more, sometimes less and sometime I receive items not related to my customer's orders. I would like to add a status column to table 2, to identify whether the items received are (i) not related to my orders, (ii) the correct amount of items, (iii) more items than needed or (iv) less items than needed +which Customer's orders are at risk. The status is checked weekly, so I have provided multiple weeks of data, but stock is not transferable between weeks. 

 

Table1

CustomerWeekItemOrdered
Customer A26ABC-0110
Customer B26ABC-0250
Customer C26ABC-0360
Customer A27ABC-01110
Customer C27ABC-0320
Customer D27ABC-0495
Customer C28ABC-0380
Customer D28ABC-0350
Customer E28ABC-0320
Customer F28ABC-0315
Customer D28ABC-0420
Customer G28ABC-0460
Customer C29ABC-0360
Customer D29ABC-0390
Customer E29ABC-0360
Customer F29ABC-0350
Customer D29ABC-0420
Customer G29ABC-0415
Customer E29ABC-0515
Customer F29ABC-055

 

 

Table2

WeekItemReceivedStatus
26ABC-0110 
26ABC-0255 
26ABC-0365 
27ABC-01105 
27ABC-0315 
27ABC-04100 
28ABC-0120 
28ABC-0390 
28ABC-0480 
28ABC-0511 
29ABC-03120 
29ABC-040 
29ABC-050 

 

 

Illustration of the order relationship

scott_od_0-1689957957087.png

 

Desired Outcome

scott_od_1-1689958034868.png

 

Thanks in advance to anyone spending time & effort to help me with this.

 

 

1 ACCEPTED SOLUTION
scott_od
Frequent Visitor

I've managed to resolve this now, I'm not sure it's the most elegant or efficient solution, but it gives the result I was looking for:

  1. Load both Table 1 and Table 2 into Power Query.
  2. Add 'Key' column to both Table 1 and Table 2 ('Week'-'Item')
  3. New Query 'Table 3' based on Table 1
    • Group by 'Key' (Sum 'Ordered')
    • Merge Table 1 and Table 2 using 'Key'
    • Expand merged table with 'Received'
    • Add a custom column "Status' with the following formula:
      • if [Received] = [Ordered] then "Correct amount"
      • else if [Received] > [Ordered] then "More items"
      • else if [Received] < [Ordered] then "Less items"
      • else "Not related"
  4. Merge Table 1 and Table 3 using 'Key'
  5. Expand merged table with 'Received' and 'Status'

View solution in original post

3 REPLIES 3
scott_od
Frequent Visitor

I've managed to resolve this now, I'm not sure it's the most elegant or efficient solution, but it gives the result I was looking for:

  1. Load both Table 1 and Table 2 into Power Query.
  2. Add 'Key' column to both Table 1 and Table 2 ('Week'-'Item')
  3. New Query 'Table 3' based on Table 1
    • Group by 'Key' (Sum 'Ordered')
    • Merge Table 1 and Table 2 using 'Key'
    • Expand merged table with 'Received'
    • Add a custom column "Status' with the following formula:
      • if [Received] = [Ordered] then "Correct amount"
      • else if [Received] > [Ordered] then "More items"
      • else if [Received] < [Ordered] then "Less items"
      • else "Not related"
  4. Merge Table 1 and Table 3 using 'Key'
  5. Expand merged table with 'Received' and 'Status'
rubayatyasmin
Super User
Super User

Hi, @scott_od 

 

follow the steps 

 

  1. Load both Table 1 and Table 2 into Power Query.
  2. Merge the tables based on the "Item" column.
  3. Expand the merged table to include "Customer" and "Ordered" columns.
  4. Add a custom column with the following formula:
    • `if [Received] = [Ordered] then "Correct amount"
    • `else if [Received] > [Ordered] then "More items"
    • `else if [Received] < [Ordered] then "Less items"
    • else "Not related"
  5. Remove unnecessary columns.
  6. Close & Load the modified Table 2 back into Excel.

adjust the logic with your exact value

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Hi @rubayatyasmin 

thanks for your suggestion, but the out does not provide the correct result, as it seems to duplicate items & weeks:

scott_od_0-1690001550552.png

 

I tried adapting your suggestion & doing the merge based on "item" and "week" but in that scenario the results are incorrect for those orders where the total received amount is higher than the individual order, when in fact the total received amount is not enough to cover the item orders for that week

scott_od_1-1690001733273.png

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors