Excel Pivot Table add % column - excel

I have a Pivot:
City HC TC
--------------------------------
London 50 100
Manchester 67 250
Leeds 20 20
All I need to do is, within the Pivot table, add another column that calculates the percentage based on the second and third columns.
The outcome would be:
City HC TC
--------------------------------
London 50 100 50%
Manchester 67 250 27%
Leeds 20 20 100%

Under Fields, Items & Sets click Calculated Field... and add your formula that's dependent on other columns in the Pivot table.
Example:
The database:
The Pivot table (with Field2 formula: = Revenue / Units):

Related

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?

How to join 1.5 million rows of data based on 15 fields

I have a fact table of sales data from the year 2019, which has about 1.5 million rows of data. I need to compare 2019 sales with 2018 sales. The 2018 sales fact table also has about 1.5 million rows of data.
Each fact table has 15 of the same columns which include fields such as date, category, department, location, etc.
Date
Field 1
Field 2..
…field 15
Sales
01.01.18
ABC
XYZ
A12
100
01.02.18
ABCD
XXY
A13
200
01.03.18
ABB
XYY
A14
300
01.04.18
ACC
ZXX
A15
400
Date
Field 1
Field 2..
…field 15
Sales
01.01.19
ABC
XYZ
A12
110
01.02.19
ABCD
XXY
A13
210
01.03.19
ABB
XYY
A14
310
01.04.19
ACC
ZXX
A15
410
I need to have 2018 sales and 2019 sales in two columns that are next to each other.
I have tried this through a left join (matching the minimum amount of fields needed for a correct mapping) , but then my PC ran out of memory. I also tried doing this through power pivot, but my PC also ran out of energy while attempting to load the second fact table to the data model.
How can I have 2018 Sales and 2019 Sales, with the correct mapping, in columns next to each other?
Date '18
Date '19
Field 1
Field 2..
…field 15
Sales 2018
Sales 2019
01.01.18
01.01.19
ABC
XYZ
A12
100
110
01.02.18
01.02.19
ABCD
XXY
A13
200
210
01.03.18
01.03.19
ABB
XYY
A14
300
310
01.04.18
01.04.19
ACC
ZXX
A15
400
410
Assuming the csv data is imported to Sheet2(2018) & Sheet3(2019) via Data > Get External > From text. Put this in Sheet A1 :
=OFFSET(INDIRECT(CHOOSE(2-MOD(COLUMN(),2),"Sheet2","Sheet3")&"!A1",TRUE),ROW()-1,INT(COLUMN()/2+0.5)-1)
and drag right+downwards.
Idea : use column() with mod(), to 'drive' offset cell selection. choose() do the sheet selection.
Please share if it works/not. ( :

Sorting an Excel Pivot Table by a calculated field

I have the following Excel spreadsheet:
A B C D
1 Product Category Sale Margin
2 Product A Apparel 500 45%
3 Product A Apparel 400 30%
4 Product A Shoes 600 55%
5 Product B Apparel 300 20%
6 Product C Beauty 100 40%
7 Product C Shoes 200 65%
8 Product D Apparel 450 25%
9 Product D Beauty 700 50%
10 Product D Beauty 250 35%
Based on this data I create a Pivot Table.
In this Pivot table I added the following Calculated Field to get the profit:
Profit = Sale * Margin
which leads to the following Pivot Table:
Sum of Profit
Product A 1.950
Product B 60
Product C 315
Product D 1.540
Now, I want to sort this Pivot Table descending so it looks like the following:
Sum of Profit
Product A 1.950
Product D 1.540
Product C 315
Product B 60
It seems that for a Calculated Field the sorting options in the PivotTable-Tools is not available.
Do you have any other idea how I can achieve this sorting?
NOTE: I know that I could add the calculation of the profit in Column E in the source data. However, my original file is a bit more complex compared to the simplified example above so a Calculated Field is unavoidable.
It seems that Pivot Tables are unable to sort in usual ways if there is more than one field in the rows section (categorical data). I've tried it in multiple pivot table layouts and it even holds true in the "traditional" pivot table layout. If it's necessary to have more than one categorical element I believe concatenation would be a work-around.
Right click on a cell in the Calculated Field --> Sort --> Sort largest to smallest.
Or you can try the following code to sort the calculated field.
Sub SortCalculatedField()
Dim ws As Worksheet
Dim pt As PivotTable
Set ws = Sheets("Sheet1") 'This is the sheet which contains Pivot Table
Set pt = ws.PivotTables(1)
pt.PivotFields("Product").AutoSort xlDescending, "Sum of Profit", pt.PivotColumnAxis.PivotLines(1), 1
End Sub

Multiple pivots in Excel

I am working with Excel and have a pivot table like so:
[ Gender, pivot ]
Year > Quarter Male Female
[-] 2014 64% 36%
Q1 60% 40%
Q2 70% 30%
Q3 60% 40%
Q4 60% 40%
This would have what I call two two row-aggregations (Year, Quarter) and one column-aggregation or pivot (Gender). Is there a way to have multiple pivots, for example having it with one row-aggregation (Year) and two column-aggregations (Quarter, Gender)
Year [Quarter > Gender ]
Q1 Q2 Q3 Q4
M | F M | F M | F M | F
2014 60 | 40 70 | 30 60 | 40 60 | 40
If this is not possible, are there other tools that would allow me to do multiple pivots? Is this a common use case in data-analysis, having multiple pivots?
Sure, Move the Quarter into the "Column labels" box (above values)
In addition to user3240704's post, when you group the dates, the smallest unit you choose in the grouping dialog will be showing with the original column name. If you group by Year, Quarter and Month on a column called "MyDate", you will see Year, Quarter and "MyDate" in the field list and can drag "Quarter" to the column labels as described. If your grouping is only on Year and Quarter, you will not see a "Quarter" field and will need to drag the "MyDate" field into the column labels field well.
In the screenshot, my date field is called "date" and grouped by Year and Quarter.

Adding a Column with Condition on Pivot Table

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)

Resources