Google-sheets – Create table showing difference between values in two pivot tables

google sheetsimportrangepivot table

Our bookstore has two separate documents in Google Sheets (one containing purchase data and one with sales data). Each document contains a sheet with a pivot table that sums up total purchases/sales by book category. I wanted to create a third sheet that shows the difference between the two (i.e. profit margin by category).

I was able to find the IMPORTRANGE function that can pull the data range from one sheet to another, but I cannot figure out how to generate a new pivot table showing the difference between the two tables.

Can someone explain to me how to do this? (Assume for the sake of simplicity that the two documents are named A and B and that the data is in a sheet called Sheet 1 in each of them, each with two columns Section and Total).

EDIT: Here are two screenshots of the pivot tables I'm trying to get the difference of. They are in separate documents, and Google Sheets will import them into a single document, saying that the data is too large …

enter image description here

enter image description here

Best Answer

Use IMPORTRANGE() to import data and VLOOKUP() to find match between Product Section.

Here's a sample :

First you need to import data from another sheet with IMPORTRANGE()

You need to accept the access between sheets when you use IMPORTANGE: The best is to do this with a sample of every sheets to be sure you allow access for each one.

To find match between sections use VLOOKUP

=ArrayFormula(
        ArrayFormula(
              VLOOKUP(D3:D10,IMPORTRANGE("https://docs.google.com/spreadsheets/d/1lQ8vwvrzvo-kg-FkeZVapeUHoebf8t6ISbHD2kCMc7w/edit#gid=0","Sheet1!$A$3:$B$10"),2,false))

-IMPORTRANGE("https://docs.google.com/spreadsheets/d/1lQ8vwvrzvo-kg-FkeZVapeUHoebf8t6ISbHD2kCMc7w/edit#gid=0","Sheet1!E3:E10"))

A3:B10 is the range containing price and section 1 labels from sheet 1
D3:D10 is section 2 labels range from sheet 2
E3:E10 is the price column from sheet 2
https://docs.google.com/spreadsheets/d/1lQ8vwvrzvo-kg-FkeZVapeUHoebf8t6ISbHD2kCMc7w/edit#gid=0 is my spreadsheet