Pivot table Programming in VBA - excel

I have a data Excel sheet in the below format:
Name Fruits Condition of Fruits
===== ====== ====================
Ram Apple Good
Jadu Apple Bad
Tina Orange Good
Ram Orange Good
Tina Apple Bad
Ram Apple Bad
Output of the Pivot program in the other sheet of the same excel, say in sheet(2) should be
like this:
Name Fruits Condition of Fruits
==== ====== ===================
Good Bad Total
==== ===== ======
Ram Apple 1 1 2
Ram Orange 1 0 1
Tina Apple 0 1 1
Tina Orange 1 0 1
jadu Apple 0 1 1
===================================
Grand Total 3 3 6
===================================
The above format needs to be present in the Excel in the sheet(2), whenever sheet(1) will be having source data within it as shown in the first table.
I want Macro program to create using Excel pivot table concept.

If you insert a pivot table on your data, drag these columns into the Row Labels:
Name
Fruit.
Then drag this column into the Column Labels:
Condition of Fruit.
Drag the same column into Values:
Condition of Fruit.
The pivot table looks almost the same as yours (except the fruit comes under the name, instead of repeating the name for each fruit).
Whenever you update the data in sheet 1, you may have the pivot table reflect this by right-clicking on the table and choosing Refresh.

Related

excel : determine if a combination of several cells exists and output result

Considering the following data :
sheet1 (customers)
A
0 customer_name
1 john
2 kevin
3 mickael
sheet2 (products)
A
0 product_name
1 book
2 ball
3 game
sheet3 (orders)
A B
0 customer_name product_name
1 john book
2 john game
3 mickael ball
I would like to know for each combination of customer and product if an order has been ordered and display it in the sheet1 to get something like that :
sheet1 (customers updated )
A B C D
0 customer_name book ball game
1 john 1 0 1
2 kevin 0 0 0
3 mickael 0 1 0
I know how to do that with "code" (by doing a macro in vba or a small exe in c# that will update the file), but I want to do it (if its possible) by just setting a formula inside my sheet (fyi, I can put the 3 inputs in the same sheet if needed, that's not a constraint
Updated :
with the previous configuration described, I have put the following formula in sheet1 B2 : =COUNTIFS(Sheet3!$A:$A;$A2;Sheet3!$B:$B;B$2), and when running the formula and extending it to every cell in my sheet I am getting everywhere the value #NAME? (I've translated if from french so I am not sure if its the right error in english). I think where I am making a mistake is that I am not using sheet2, how can I say first to "do all the combinations possible of customers insheet1 and products in sheet2 and look for those combinations in sheet3, knowing that I am in sheet1 and that I want to display the result like aking before?
Use COUNTIFS:
=COUNTIFS(Sheet3!$A:$A,$A2,Sheet3!$B:$B,B$1)

Sort this data in excel kinda like a pivot

All,
I have this data I pulled from a database that I need to readjust. Here it is:
ID | Type | total
1 Purchase 12
1 Return 2
1 Exchange 5
3 Purchase 34
3 Return 4
3 Exchange 2
The desired result is:
ID | Purchase | Return | Exchange
1 12 2 5
3 34 4 2
and so on with a lot more data. Can this be done?
In Excel, format the data like so:
Choose a cell in these data, go to Insert -> PivotTable, insert it where you would like, and use the following settings:
This gives
Under "Design" in the Ribbon (make sure that your PivotTable is selected), go to Grand Totals -> Off for Rows and Columns. This gives
Click the "Exchange" cell and go toward the top of it, right below the "Column Labels" cell - you will see that the arrowhead will change and you can drag the column:

Excel macro store value of vlookup and then add them up

So I have the following sheet setup:
Sheet 1
A B C
Tomatoes 100 50
Onions 20 0
Garlic 10 0
Chicken 0 100
Cheese 0 20
Where each column after A is a recipe and going down is the amount of grams required in the recipe of the ingredient.
Sheet 2 has cost per 100 grams per ingredient like so:
A B
Chicken 10
Tomatoes 1.5
Onions 2.25
What I'd like to do, is at the bottom of sheet 1 (ideally) under each column I could have the cost for the recipe.
In my mind it's broken down into 2 steps. Step 1 is do a vlookup from Sheet 1 to replace the grams to cost. Then do a sum of the entire column. I just don't know how to do that either in a macro or formula.
Refer the below specified link,
https://www.ablebits.com/office-addins-blog/2014/08/05/excel-vlookup-sum-sumif/#lookup-sum
You can download their worksheet here

Multiple value lookup accross excel sheets

I have a master worksheet and a Extract worksheet.
I want to extract data from Extract sheet and present it as follows in the master sheet.
Data is as follows:
Extract Sheet
--------------------------------------
Fruit Nutrients Proportion
Apple Calcium 10
Apple Vitamin B 20
Mango Vitamin A 50
Lemon Vitamin C 30
Lemon Vitamin A 10
Master Sheet
--------------------------------------------------------
Fruit Calcium Vitamin A Vitamin B Vitamin C
Apple 10 0 20 0
Mango 0 50 0 0
Lemon 0 10 0 30
I have used Excel Array functions SMALL and INDEX but
I am unable to get the Proportion value in the master table.
I keep getting #NUM error
Please help me with the same and guide.
Thanks in advance.
I've put your sample data and results into a single worksheets as per the following image but you should be able to move the Extract to another worksheet and transcribe the formula for your own purposes.
    
The standard formula in F2 is =IFERROR(INDEX($C$2:$C$6,MIN(INDEX(ROW($1:$5)+(($A$2:$A$6<>$E2)+($B$2:$B$6<>F$1))*1E+99,,))),0). Fill both right and down as necessary. You mentioned using SMALL but you have no duplicated values across the two criteria columns so I think this is closer to what you require. Post back a comment if you do need a SMALL function with k picking the first, second, etc.
Try this:
=IFERROR(LOOKUP(2,1/(('Extract '!$A$2:$A$6=$A2)*('Extract '!$B$2:$B$6=B$1)),'Extract '!$C$2:$C$6),0)

Calculate Percentages on Excel Pivot Table Totals

I have Excel source data with Phase, Team, and Early or Late. I've created a pivot table to summarize the data like this:
Team 1 | Team 2 |
Phase Early | Late | Total | Early | Late | Total | Grand Total
---------------------------------------------------------------------
Phase 1 2 3 5 0 1 1 6
Phase 2 4 5 9 2 2 4 13
Phase 3 5 6 11 1 1 2 13
Grand Total 11 14 25 3 4 7 32
I'd like to calculate percentages of the totals (so the total early for team 1 divided by the total for team 1--or 11/25 for 44% early, and then the total late divided by the total, or 14/25 for 56% late).
I tried using formulas below the pivot table, which worked great, but they get out of whack if the source data doesn't have records that fall in a column (so if there are no late items for Team 2, that column disappears). Is there an easy fix or a way to keep the pivot table at a set number of rows or columns?
Instead of constructing formulas separately from the pivot table you can just set the pivot table to calculate the percentages directly. That way you don't have to worry about how many columns and rows are in the pivot table. In Excel 2010 (2007 s/b the same too) go to the PivotTable Tools ribbon then options and under calculations click the dropdown Show Values As and select % of Parent Column Total.

Resources