Adding a Column with Condition on Pivot Table - excel

Been trying to figure this out for a while -
If I have a situation in which my pivot table gives me something along the lines of:
Row Labels Revenues
Panera 25
Pasta 15
Salad 10
Olive Garden 40
Sandwich 20
Pasta 20
and I wanted to insert a column next to revenues with 0's only for the rows with headers (panera, olive garden) and leave the rest of the rows for the orders blank - i.e.
Row Labels Revenues Order #
Panera 25 0
Pasta 15
Salad 10
Olive Garden 40 0
Sandwich 20
Pasta 20
is there a way to do this either in VBA, or just with a formula? Within my pivot table, the headers are labeled "restaurant name" while the subsets are labeled "orders", I was thinking about saying something along the lines of - if it's a restaurant name, insert 0, otherwise leave blank - but not sure how to do that or if there's an easier way?

If there is no overlap of names of restaurants and names of orders (i.e. you don't have a restaurant called "Pasta" for instance), you could use a formula such as
=IF(IFERROR(VLOOKUP(A3,'Sheet2'!A:A,1,FALSE),"")="","",0)
(assuming your pivot table was extracting the original data containing the restaurant name from column A of Sheet2)

Related

extract values based on two columns

I would like to extract a price value based on two other columns. In table 1, I am given the raw data where I want to draw from. In Table 2, I am given only the contract number, and I would like to find the type being "Mater" and have the price listed out for it.
I've tried to use this formula but I don't think I am calling the columns correctly.
=IF(AND(Table2!A1=Table1!$A$1:$A$6,Table1$C$1:$C$6="Mater"),Table1!$D$2:$D$6,"")
Is there a formula using index match, if(and), or another one that could work in this case?
Thank you!
Table 1.
Contract
Work
Type
Cost
5321a
aaa
Labor
52
5321a
ab
Mater
57
5641a
aba
Mater
10
536451a
aae
Labor
75
2441a
aan
Labor
42
53421
aar
Mater
14
Table 2
Contract
Mater Cost
5321a
57
5641a
57
53421
14
The following should work:
=SUMIFS(Sheet1!D2:D7,Sheet1!A2:A7,A2,Sheet1!C2:C7,"Mater")
(I'm assuming the first table in on Sheet1)

Excel Pivot Table: Different Subtotals for Different Value Fields

I have an excel pivot table with two summed field values. I need to subtotal the first one using sum and the second one using average. Here is the desired output:
Region
State
SumOfSales
SumOfUnitsSold
A
NY
100
5
A
NJ
200
3
A Subtotal
300
4
B
FL
250
4
B
GA
300
2
B Subtotal
550
3
So far the closest thing I've been able to find is a custom subtotal through the field settings for Region. But this adds two rows for subtotals. Any ideas?

Excel Pivot table subtotal with element exclusion

I want to add the extra line of Grand Total of the pivot table,
which excludes some element group. Is it possible to do this?
For example, I want to add subtotal of [East excluded New York Total],
is it possible without adding the additional column for grouping purpose from the source data/worksheet?
Because I further want [East + West Total]
and [East excluded New York + West Total]. The approach of adding extra group label columns is not flexible enough as the group subset is not static (i.e., New York sometimes is a subset of East, sometimes not,
for showing subtotal). Thanks.
eg.
East
New York 100
Boston 200
Philadelphia 300
[East excluded New York Total] 500
East Total 600
West
XXX 999
YYY 999
XXX 999
West Total 999
---------------
[East excluded New York + West Total] 999
GrandTotal 9999
Presuming the cities are in Column A and start with A2 and ends wit A5, then resulting cell will be:
=SUMIF(A2:A5, <>"New York", B2:B5)
will do the trick.
Though to be noted, pivot tables were never intended to yield extra rows and it may actively hurt your table structure.
Easiest solution to not get interfering dynamic ranges would be to treat East Coast and Web Coast as seperate Pivot Field Columns instead of Field Rows.
This way, you can apply the formula to entire [#Column]

Lookup and replace specific values with reference in pivot table

If I'm trying to find specific names in a list given from my pivot table such as -
Row Labels Revenues Order #
Panera 25 0
Pasta 15
Salad 10
Olive Garden 40 0
Sandwich 20
Pasta 20
Panda Express 30 0
Rice 15
Chicken 15
And I want to search through my document, find Olive Garden and Panda Express and I wanted to replace the 0 in the order # column with 10 for Olive Garden and 20 for Panda Express. Currently, someone here helped me out with
=IF(IFERROR(VLOOKUP(A9,worksheet!K:K,1,FALSE),"")="","",0)
which inserts 0's for the headers and blanks for the orders in the 'Order #' column, can I add a second formula that would find the names and replace the value in that column? Or adjust the current formula?
Quick note - order # column is not from the pivot table.
To make it more clear, - I am getting data from an external source (i.e. paper invoices), as opposed to making a manual entry to adjust the 0's in the order # column, I would like to tell VBA/Excel - "hey Olive Garden's order number is 10 and Panda Express's order number changed to 20, adjust".
this is my end goal -
Row Labels Revenues Order #
Panera 25 0
Pasta 15
Salad 10
Olive Garden 40 10
Sandwich 20
Pasta 20
Panda Express 30 20
Rice 15
Chicken 15
If you have a range with the restaurant names in one column and the order numbers in the next column (say columns X and Y of the sheet called "worksheet"), you could change your formula to be
=IF(IFERROR(MATCH(A9,worksheet!K:K,0),"")="","",IFERROR(VLOO‌​KUP(A9,worksheet!X:Y‌​,2,FALSE),0))
(P.S. Changed the original VLOOKUP to MATCH based on useful feedback from teylyn.)
FWIW, that formula would be better using MATCH, not VLookup, since it's returning the value from the first column.
But back on track: what are you trying to achieve? Change the values in a pivot table?
First, a formula cannot change values in another cell.
Second, a pivot table reports on existing data. You can't change the numbers that a pivot table reports.
You will need to re-think your approach. If you don't like the numbers the pivot table returns, you'll need to change the underlying source data.

Excel: Combine Multiple Rows and Adding Similar Columns

Hopefully this is an easy question: I need to combine some similar rows in a spreadsheet but I need to add the values in one of the columns. For example, the data looks like this:
Result Count ID
100 75 xxx
100 10 xxx
100 5 xxx
95 35 yyy
95 40 yyy
95 10 yyy
I would like to combine all rows so that there is just one row for ID xxx and one row for yyy so that the final spreadsheet would look like:
Result Count ID
100 114 xxx
95 75 yyy
I know that I could probably use sum but I'm dealing with several thousand rows of data and was wondering if there is a way to do this more quickly.
Your example does not make sense, the numbers don't add up. Can you also have something like:
Result Count ID
100 114 xxx
95 75 xxx
80 70 yyy
I guess you could get very far with pivot tables. There are many other ways but pivot tables are more visual and easily customisable.
Select your data, go to the Data menu and click on Pivot table. The pivot table builder will pop up. Drag the ID column into the Row Labels list, drag the Count into the Values list and Result into the Row labels list again.
You can actually slice and dice your dataset any way you want with the pivot tables. To learn more just pop-up the help(F1) for pivot tables and follow some examples.

Resources