Using data in formulas from different worksheets

%3CLINGO-SUB%20id%3D%22lingo-sub-2030594%22%20slang%3D%22en-US%22%3EUsing%20data%20in%20formulas%20from%20different%20worksheets%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2030594%22%20slang%3D%22en-US%22%3EI%20have%20two%20different%20worksheets%20that%20are%20tables%20with%20data%20that%20is%20listed%20by%20city.%20Each%20worksheet%20is%20a%20separate%20day.%20I%20want%20to%20calculate%20the%20difference%20in%20the%20two%20days%20of%20revenue.%20But%20some%20pages%20have%20a%20different%20amount%20of%20cities%20so%20they%20don%E2%80%99t%20necessarily%20line%20up%20to%20the%20same%20row.%20So%20New%20York%20might%20occupy%20the%20same%20row%20as%20Philadelphia%20on%20a%20different%20worksheet.%20Is%20there%20a%20way%20to%20match%20the%20names%20in%20column%201%20and%20using%20that%20row%20of%20information%20before%20calculating%20the%20formula%3F%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2030594%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2031129%22%20slang%3D%22en-US%22%3ERe%3A%20Using%20data%20in%20formulas%20from%20different%20worksheets%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2031129%22%20slang%3D%22en-US%22%3EHere%20is%20a%20sample%20the%20sample%20of%20the%20spreadsheet.%20I%20want%20to%20compare%20the%20yesterday%20columns%20on%20each%20spreadsheet%20but%20the%20cities%20change%20order%20so%20are%20not%20in%20the%20same%20row%20between%20the%20worksheets.%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E
Occasional Contributor
I have two different worksheets that are tables with data that is listed by city. Each worksheet is a separate day. I want to calculate the difference in the two days of revenue. But some pages have a different amount of cities so they don’t necessarily line up to the same row. So New York might occupy the same row as Philadelphia on a different worksheet. Is there a way to match the names in column 1 and using that row of information before calculating the formula?
6 Replies

@Jaxtonv This can be done with a variety of functions: XLOOKUP, VLOOKUP, LOOKUP, a combination of INDEX and MATCH, or others.  If you provide a sample workbook we can be a little more specific on how to use it, otherwise, just look at the help information about what values need to be passed to it.

Here is a sample the sample of the spreadsheet. I want to compare the yesterday columns on each spreadsheet but the cities change order so are not in the same row between the worksheets.

@Jaxtonv  In the attached I ended up using a SUMIFS() formula because there wasn't a single unique column to use for the lookup (i.e. there are 2x Gainsville locations).  I also used table notation which might be a little harder for you to read if you aren't familiar with it.  And lastly I added the IFERROR() and the 1/1/ to detect if nothing was found BUT if the lookup value is or could be 0 this 'trick' is not good.  But then again if when they aren't on list you prefer to assume they are 0 then simply remove the IFERROR() and the 1/1/.  Since I don't know all the details of what you need I'm trying to give you options.  

Thank you so much. If I changed the duplicate city names to unique names how would it work in that case.

Also, use table 7 as the reference. How did you determine it was table 7?

@Jaxtonv I don't know why you would bother at this point since that could be asking for errors (like in the workbook you attached you changed Gainsville to GainsvilleF and GainsvilleG on Sheet2 but not Sheet1.  But to answer your question, if the city or another column was guaranteed to be unique then you could simplify the formula slightly.  Here is the formula now:

 

=IFERROR([@YESTERDAY]-1/1/SUMIFS(Table7[YESTERDAY],Table7[CITY],[@CITY],Table7[STATE],[@STATE],Table7[COUNTRY],[@COUNTRY]),"n/a")

 

but if the CITY was unique then you could use:

 

=IFERROR([@YESTERDAY]-1/1/SUMIFS(Table7[YESTERDAY],Table7[CITY],[@CITY]),"n/a")

 

or you could replace SUMIFS with SUMIF or VLOOKUP or one of the other LOOKUP functions.

Similarly, if you want to assume that if the CITY doesn't exist on the previous list you should use 0 (zero) then it can become:

 

 

=[@YESTERDAY]-SUMIFS(Table7[YESTERDAY],Table7[CITY],[@CITY])

 

or with the original formula checking city, state, and country so you don't have to tweak the city names, it would be:

 

 

=[@YESTERDAY]-SUMIFS(Table7[YESTERDAY],Table7[CITY],[@CITY],Table7[STATE],[@STATE],Table7[COUNTRY],[@COUNTRY])

 

 

and as for how I determined it is named Table7 there are a couple ways:

a) click anywhere in the table and on the ribbon click 'Table Design' and then on the left end of the ribbon is shows Table Name

b) when you are creating a formula you can click on a header in the table and it will automatically insert that table column in table reference style

c) if you already have an idea of what the table name might be, you can start to type it while entering a formula and that name will be listed as an option to autocomplete

 

Thank you very much it's a huge help