Nested If Statements (Multiple)

Excel2021

New Member
Joined
Mar 26, 2021
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am having issues getting a complex IF statement working. I have three sheets: "Summary", "Filtered COGS Data" & "Filtered Sales Data". To simplify assume That the "Summary" sheet has 2 columns named "Identifier" and "Customer/Vendor" (Columns A-B) and the other sheets have 3 columns named "Identifier", "Customer" and "Vendor" in columns A-C. The data in these columns are stored from A2:B9 (Headers A1-B1) on the "Summary" and A2:C9 (Headers A1-C1) on the other sheets. I am trying to use IF statements and Xlookups from the "Summary" sheet to both the "Filtered COGS Data" & "Filtered Sales Data" using the "Identifier columns on each sheet (Lookup value will be the identifier column on the summary sheet). The customer or vendor can appear in 1 of the 4 columns across the "Filtered COGS Data" & "Filtered Sales Data" sheets depending on the ERP system data. I am trying to pull whichever column has this into the "Customer/Vendor" column on the summary sheet by eliminating the remaining columns using checks to ensure they <> "" or <>0. My formula which does not work is as follows:

=IF($A2="","",
IF(IF(AND(XLOOKUP($A2,'Filtered COGS Data'!$A$2:$A$9,'Filtered COGS Data'!$B$2:$B$9,0,0,1)<>0,XLOOKUP($A2,'Filtered COGS Data'!$A$2:$A$9,'Filtered COGS Data'!$B$2:$B$9,0,0,1)<>""),XLOOKUP($A2,'Filtered COGS Data'!$A$2:$A$9,'Filtered COGS Data'!$B$2:$B$9,0,0,1),
IF(IF(AND(XLOOKUP($A2,'Filtered Sales Data'!$A$2:$A$9,'Filtered Sales Data'!$B$2:$B$9,0,0,1)<>0,XLOOKUP($A2,'Filtered Sales Data'!$A$2:$A$9,'Filtered Sales Data'!$B$2:$B$9,0,0,1)<>""),XLOOKUP($A2,'Filtered Sales Data'!$A$2:$A$9,'Filtered Sales Data'!$B$2:$B$9,0,0,1),
IF(IF(AND(XLOOKUP($A2,'Filtered Sales Data'!$A$2:$A$9,'Filtered Sales Data'!$C$2:$C$9,0,0,1)<>0,XLOOKUP($A2,'Filtered Sales Data'!$A$2:$A$9,'Filtered Sales Data'!$C$2:$C$9,0,0,1)<>""),XLOOKUP($A2,'Filtered Sales Data'!$A$2:$A$9,'Filtered Sales Data'!$C$2:$C$9,0,0,1),
IF(IF(AND(XLOOKUP($A2,'Filtered COGS Data'!$A$2:$A$9,'Filtered COGS Data'!$C$2:$C$9,0,0,1)<>0,XLOOKUP($A2,'Filtered COGS Data'!$A$2:$A$9,'Filtered COGS Data'!$C$2:$C$9,0,0,1)<>""),XLOOKUP($A2,'Filtered COGS Data'!$A$2:$A$9,'Filtered COGS Data'!$C$2:$C$9,0,0,1),"")))))))))

Thanks
 

Attachments

  • Summary Sheet Excel.PNG
    Summary Sheet Excel.PNG
    41.3 KB · Views: 4
  • Filtered COGS Sheet Excel.PNG
    Filtered COGS Sheet Excel.PNG
    34.1 KB · Views: 5
  • Filtered Sales Sheet Excel.PNG
    Filtered Sales Sheet Excel.PNG
    31.6 KB · Views: 5

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
See if this works for you:
Book1
AB
1IdentifierCustomer/Vendor
21Orange Co
32Yellow Co
43Yellow Co
54Orange Co
65Apple Co
76Lemon Co
87Red Co
98Blue Co
Sheet1
Cell Formulas
RangeFormula
B2:B9B2=BYROW(A2:A9,LAMBDA(r,LET(x,XLOOKUP(r,$A$2:$A$9,HSTACK('Filtered COGS Data'!$B$2:$C$9,'Filtered Sales Data'!$B$2:$C$9)),y,IF(x=0,"",x),FILTER(y,y<>""))))
Dynamic array formulas.


Book1
ABC
1IdentifierCustomerVendor
21Orange Co
32Yellow Co
430
54Orange Co
650
76
87
98
Filtered COGS Data


Book1
ABC
1IdentifierCustomerVendor
210
320
43Yellow Co0
54
65Apple Co
76Lemon Co
87Red Co
98Blue Co
Filtered Sales Data
 
Upvote 0
See if this works for you:
Book1
AB
1IdentifierCustomer/Vendor
21Orange Co
32Yellow Co
43Yellow Co
54Orange Co
65Apple Co
76Lemon Co
87Red Co
98Blue Co
Sheet1
Cell Formulas
RangeFormula
B2:B9B2=BYROW(A2:A9,LAMBDA(r,LET(x,XLOOKUP(r,$A$2:$A$9,HSTACK('Filtered COGS Data'!$B$2:$C$9,'Filtered Sales Data'!$B$2:$C$9)),y,IF(x=0,"",x),FILTER(y,y<>""))))
Dynamic array formulas.


Book1
ABC
1IdentifierCustomerVendor
21Orange Co
32Yellow Co
430
54Orange Co
650
76
87
98
Filtered COGS Data


Book1
ABC
1IdentifierCustomerVendor
210
320
43Yellow Co0
54
65Apple Co
76Lemon Co
87Red Co
98Blue Co
Filtered Sales Data
Thanks for this. I didn't mention this as I didn't think it would come up but the A "identifier" column on my actual file is already using the filtered formula so I don't think this will work for me. I need a non-array formula for this.
 
Upvote 0
Why not? Have you tried it? Just replace the "A2:A9" in the BYROW and the XLOOKUP with the formula you have in column A.
 
Upvote 0
I have tried it but the results are not correct when I apply it to my other file. It brings in way more rows than I am expecting. It may be because the columns are not next to each other on the actual file.
 
Upvote 0
It may be because the columns are not next to each other on the actual file.
Yes, that could do it if your sample is not a true representation of your actual data. And if you didn't adjust the formula provided to fit your data.
 
Upvote 0
Yes, that could do it if your sample is not a true representation of your actual data. And if you didn't adjust the formula provided to fit your data.
I did adjust it to my file when I tried but it didn't give the results I was expecting.
 
Upvote 0
I think I figured this out. I changed my existing formula and it seems to be working now.

This is what worked for me.

=IF(A2="","",IF(AND(XLOOKUP(A2,'Filtered COGS Data'!A2:A9,'Filtered COGS Data'!B2:B9,"",0)<>"",XLOOKUP(A2,'Filtered COGS Data'!A2:A9,'Filtered COGS Data'!B2:B9,"",0)<>0),XLOOKUP(A2,'Filtered COGS Data'!A2:A9,'Filtered COGS Data'!B2:B9,"",0),IF(AND(XLOOKUP(A2,'Filtered COGS Data'!A2:A9,'Filtered COGS Data'!C2:C9,"",0)<>"",XLOOKUP(A2,'Filtered COGS Data'!A2:A9,'Filtered COGS Data'!C2:C9,"",0)<>0),XLOOKUP(A2,'Filtered COGS Data'!A2:A9,'Filtered COGS Data'!C2:C9,"",0),IF(AND(XLOOKUP(A2,'Filtered Sales Data'!A2:A9,'Filtered Sales Data'!B2:B9,"",0)<>"",XLOOKUP(A2,'Filtered Sales Data'!A2:A9,'Filtered Sales Data'!B2:B9,"",0)<>0),XLOOKUP(A2,'Filtered Sales Data'!A2:A9,'Filtered Sales Data'!B2:B9,"",0),IF(AND(XLOOKUP(A2,'Filtered Sales Data'!A2:A9,'Filtered Sales Data'!C2:C9,"",0)<>"",XLOOKUP(A2,'Filtered Sales Data'!A2:A9,'Filtered Sales Data'!C2:C9,"",0)<>0),XLOOKUP(A2,'Filtered Sales Data'!A2:A9,'Filtered Sales Data'!C2:C9,"",0),)))))
 
Upvote 0
Solution

Forum statistics

Threads
1,224,814
Messages
6,181,124
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top