Adding Conditions to an Existing XLOOKUP Formula

meppwc

Well-known Member
Joined
May 16, 2003
Messages
626
Office Version
  1. 365
Platform
  1. Windows
I would greatly appreciate assistance with adding logic to an existing formula.
The following formula is in cell W48.
=XLOOKUP(O48,'FMA TABLE'!A:A,'FMA TABLE'!C:C)

I want to add logic (conditions) to what column is used to map data from when a value is found.
Currently it is always mapping data back from 'FMA TABLE'!C:C

The logic that I want to add is:
If a value is found in O48, then if the value in P48 = “BLACK AND WHITE METER”, then map data back from TABLE'!D:D
If a value is found in O48, then if the value in P48 = “COLOR METER”, then map data back from TABLE'!E:E
If a value is found in O48, then if the value in P48 = “TOTAL METER”, then map data back from TABLE'!C:C
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
you are not looking up a value in a table only if it exists
so a countifs() may work instead

something like

=IF( AND( P48 = “BLACK AND WHITE METER” , COUNTIFS('FMA TABLE'!A:A, O48)>0) , XLOOKUP(O48,'FMA TABLE'!A:A,'FMA TABLE'!D:D), IF( AND( P48 = “color meter” , COUNTIFS('FMA TABLE'!A:A, O48)>0) , XLOOKUP(O48,'FMA TABLE'!A:A,'FMA TABLE'!E:E),IF AND( P48 = “Total METER” , COUNTIFS('FMA TABLE'!A:A, O48)>0) , XLOOKUP(O48,'FMA TABLE'!A:A,'FMA TABLE'!C:C),"")))

A SMALL sample spreadsheet, around 10-20 rows, would help a lot here, with all sensitive data removed, and expected results mocked up and manually entered, with a few notes of explanation.

MrExcel has a tool called “XL2BB” that lets you post samples of your data and will allow us to copy/paste your sample data into our Excel spreadsheets, saving a lot of time.

You can also test to see if it works ok, in the "Test Here" forum.

OR if you cannot get XL2BB to work, or have restrictions on your PC , then put the sample spreadsheet onto a share
I only tend to goto OneDrive, Dropbox or google docs , as I'm never certain of other random share sites and possible virus.
Please make sure you have a representative data sample and also that the data has been desensitised, remember this site is open to anyone with internet access to see - so any sensitive / personal data should be removed
 
Upvote 0
I tried this formula in W48 and it resulted in an error. Is the syntax correct.
 
Upvote 0
yep, i did put in a sheet

so maybe there is an issue in the lookup tables -

Book1
A
1 
Sheet1
Cell Formulas
RangeFormula
A1A1=IF( AND( P48 = "BLACK AND WHITE METER", COUNTIFS('fma table'!A:A, O48)>0), XLOOKUP(O48,'fma table'!A:A,'fma table'!D:D), IF( AND( P48 = "color meter", COUNTIFS('fma table'!A:A, O48)>0), XLOOKUP(O48,'fma table'!A:A,'fma table'!E:E),IF( AND( P48 = "Total METER", COUNTIFS('fma table'!A:A, O48)>0), XLOOKUP(O48,'fma table'!A:A,'fma table'!C:C),"")))


I have a blank sheet called FMA TABLE

can you give some of the content

I'll try a few values in the cells and see what I get back
 
Upvote 0
maybe... XLOOKUP( O4
I would greatly appreciate assistance with adding logic to an existing formula.
The following formula is in cell W48.
=XLOOKUP(O48,'FMA TABLE'!A:A,'FMA TABLE'!C:C)

I want to add logic (conditions) to what column is used to map data from when a value is found.
Currently it is always mapping data back from 'FMA TABLE'!C:C

The logic that I want to add is:
If a value is found in O48, then if the value in P48 = “BLACK AND WHITE METER”, then map data back from TABLE'!D:D
If a value is found in O48, then if the value in P48 = “COLOR METER”, then map data back from TABLE'!E:E
If a value is found in O48, then if the value in P48 = “TOTAL METER”, then map data back from TABLE'!C:C
In your "the logic that I want to add is" description only has one range being defined. to do lookups you need two ranges.
 
Upvote 0
Book1
OPQRSTUVWX
45
46
47
48lookupablack and white meterD-3
49lookupacolor metere-3
50lookupatotal meterC-3
51lookupanot 
52
53
54
55
56
57If a value is found in O48, then if the value in P48 = “BLACK AND WHITE METER”, then map data back from TABLE'!D:D
58If a value is found in O48, then if the value in P48 = “COLOR METER”, then map data back from TABLE'!E:E
59If a value is found in O48, then if the value in P48 = “TOTAL METER”, then map data back from TABLE'!C:C
60
Sheet1
Cell Formulas
RangeFormula
W48:W51W48=IF( AND( P48 = "BLACK AND WHITE METER", COUNTIFS('fma table'!A:A, O48)>0), XLOOKUP(O48,'fma table'!A:A,'fma table'!D:D), IF( AND( P48 = "color meter", COUNTIFS('fma table'!A:A, O48)>0), XLOOKUP(O48,'fma table'!A:A,'fma table'!E:E),IF( AND( P48 = "Total METER", COUNTIFS('fma table'!A:A, O48)>0), XLOOKUP(O48,'fma table'!A:A,'fma table'!C:C),"")))


Book1
ABCDE
1
2
3lookupaB-3C-3D-3e-3
4
5
6
7
fma table
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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