I'm trying to create a calculated field in my pivot table and am having issues getting the calculation right.
Consider the following "raw" pivot table:
I tried to create a calculated field that showed the net availability for an application (general formula: (Availability-Downtime)/Availability). In the Calculated Field menu, I did the following:
where the Formula is =(AVERAGE(Availability)-SUM(Downtime))/AVERAGE(Availability). The result is here:
Clearly the uptime for Application A in 2012 should be (1000-35)/1000 = 96.5%, but it's not. Where am I going wrong, here?
Here is my raw data (Availability is the same for each value of Application... these values were merged from another table via VLOOKUP):
ID Application Downtime Year Availability
1 A 15 2012 1000
2 A 20 2012 1000
3 A 12 2013 1000
4 A 0 2012 1000
5 B 12 2012 1200
6 B 14 2012 1200
7 B 23 2012 1200
8 B 90 2013 1200
9 C 23 2012 1100
10 C 32 2013 1100
11 C 34 2013 1100
12 C 12 2013 1100
I believe that it's the aggregation on top that is causing the unexpected result.
For example, where as you are expecting:
(AVERAGE(Availability)-SUM(Downtime))/AVERAGE(Availability)
What effectively is being calculated is:
(SUM(Availability)-SUM(Downtime))/SUM(Availability)
(or average depending how the field in the pivot table is aggregated)
To get the the calculation that you are after you could use a helper column populated with 1's to calculate the average availability, example below:
(Availability/helper-Downtime)/(Availability/helper)
(Then sum this in the pivot table)
Related
I have a some data about an insurance product. The dataset contain information including policyno start year, time of records, premium, claim amount, claim number and etc.
The dataset looks like pretty much like this:
startyear time premium claim_amount claim_no
2019 2019Q1 100 20 5
2019 2019Q2 150 10 2
2019 2019Q3 140 12 2
2019 2019Q4 135 15 4
2019 2020Q1 110 17 3
2020 2020Q1 160 30 8
I can use pivot table to calculate two measures (percent of claim amounts to premiums and avarage claim amounts) for policies starting from a specific year and track the changes of these two measures over the time.
The pivot table will look like this:
average claim amount time|startyear
2019 2020
2019Q1 20/5 #DIV
2019Q2 30/7 #DIV
2019Q3 42/9 #DIV
2019Q4 57/13 #DIV
2020Q1 74/16 30/8
or
percent of claim
time|startyear
2019 2020
2019Q1 20/100 #DIV
2019Q2 30/250 #DIV
2019Q3 42/390 #DIV
2019Q4 57/525 #DIV
2020Q1 74/635 30/160
Now instead of dragging caculated fields, I wonder if I can create a pull down menu or use slicer to change the measures presented in my pivot table.
I am looking for a way to pull out YTD data for a spreadsheet that has the following in the A,B,C Columns.
I want it to be able to pull the current month of the year and compare YTD sales in the C column from that.
I have used =SUM(IF(YEAR(A:A)=2016,C:C,0)) to get the entire year data but want just jan - current month for each year listed.
YTD Sales Through May
2008
2009
2010
2011
2012
2013
2014
2015
2016
Jan-03 17 $86,625
Feb-03 17 $107,900
Mar-03 21 $103,400
Apr-03 17 $112,050
May-03 20 $75,145
Jun-03 26 $198,800
Jul-03 14 $80,695
Aug-03 19 $50,940
Sep-03 26 $152,380
Oct-03 23 $109,380
Nov-03 19 $113,875
Dec-03 21 $149,275
Jan-04 30 $113,110
Feb-04 17 $109,493
Mar-04 15 $69,690
Apr-04 25 $123,145
May-04 24 $136,685
Jun-04 30 $148,495
Jul-04 21 $138,990
Aug-04 29 $131,005
Sep-04 38 $165,790
Oct-04 43 $173,190
Nov-04 41 $253,915
Dec-04 39 $217,650
You would use this formula and change the Year to what you want:
=SUMPRODUCT((MONTH($A$1:$A$24)<=MONTH(TODAY()))*(YEAR($A$1:$A$24)=2016)*$C$1:$C$24)
If you want all the years YTD in one formula you can:
=SUMPRODUCT((MONTH($A$1:$A$24)<=MONTH(TODAY()))*(YEAR($A$1:$A$24)={2008,2009,2010,2011,2012,2013,2014,2015,2016})*$C$1:$C$24)
To make the formula more dynamic, so it grows and contracts with the size of the data use this;
=SUMPRODUCT((MONTH($A$2:INDEX(A:A,MATCH(1E+99,A:A)))<=MONTH(TODAY()))*(YEAR($A$2:INDEX(A:A,MATCH(1E+99,A:A)))={2004,2005})*$C$2:INDEX(C:C,MATCH(1E+99,A:A)))
Make sure that the references $A$2 and $C$2 refer to the first cell of data and not the title row.
With Array formula's calculations being exponential we need to limit the reference to only the dataset size. All the INDEX(A:A,MATCH(1E+99,A:A)) accomplish this. It will automatically set the last row with a number in column A as the last row of the dataset.
So as the dataset grows or shrinks we will not be doing any unneeded iterations.
Change {2004,2005} to any number of years desired.
I have to create a report in excel.I have to use a pivot table as datasource.
For example my pivot table is like below.
Year column is dynamic(count may decrease or increase)
Year Category Value
-----------------------------
2009 A 58
2012 A 10
2014 B 9
2013 C 7
2014 C 12
2012 C 54
2013 B 8
In my excel report I have to show like below.
Year A B C
--------------------------
2009 58 0 0
2012 10 0 54
2013 0 8 7
2014 0 9 12
--------------------------
Total 68 17 73
Please give me a solution for this.
I did not use pivot table. this is how i would do it. On the sheet with your raw data, do the following first:
The formula for column D is
=A2&B2
and the formula for column E is
=SUMIF(D:D,D2,C:C)
On a new sheet, manually enter the year for column A. Manually enter the headers "A", "B", "C" for the next 3 columns.
The formula I have used for column B is =IF(ISNA(VLOOKUP(A2&$B$1,Sheet1!D:E,2,0)),0,VLOOKUP(A2&$B$1,Sheet1!D:E,2,0))
The formula i used for column C is =IF(ISNA(VLOOKUP(A2&$C$1,Sheet1!E:F,2,0)),0,VLOOKUP(A2&$C$1,Sheet1!E:F,2,0))
and the formula i used for column D is =IF(ISNA(VLOOKUP(A2&$D$1,Sheet1!D:E,2,0)),0,VLOOKUP(A2&$D$1,Sheet1!D:E,2,0))
Hope this helps.
Cheers.
I have a requirement in which i have to pick up the initial value of each row in a crosstab..
My crosstab looks like this
value 1960 1970 2010 2011
aus 10 5 11 6
eng 5 2
bra 11 4
ind 8 11
i have to add another column which picks up the initial value for every row based on the year..
so the result should look like this.
value 1960 1970 2010 2011 initialValue
aus 10 5 11 6 10
eng 5 2 5
bra 11 4 11
ind 8 11 8
You should be able to use the minimum() function to determine the lowest value for year and then return the value corresponding to that. The expression for the initialValue data item would be something like:
total(
CASE
WHEN [Year] = minimum([Year] for [Language])
THEN [Value]
ELSE 0
END
for [Language])
We get the lowest year for the specific language in the data set using the minimum() function using the for clause to define the aggregation level. If the year of the row matches this number, we output the value, otherwise we output 0. We then total everything up for each language which should give us the value for the lowest year.
This solution assumes that the numbers displayed in your crosstab are totals of lower-level row detail. If the aggregate is something different, such as average or count, the wrapping summary function should be changed accordingly.
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.