Is there a way to switch the fields calculated using a slicer (or a pull down menu) in a excel pivot table? - excel

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.

Related

Pivot Table calculated field values are incorrect

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)

How to calculate no of days spent per month from the data in MS Excel?

I have a data which has a hotel check in date and check out date. I would be calculating the number of days spent at the hotel, I would simply subtract both of them and I have the days difference.
I now have to pick up the customers who stayed for more than 31 days and find out how many days they had spent per month. For example, some one checking in on 18th July 2015 and checked out on 18th September 2015, there should be multiple columns, corresponding to that cust which reads 13 31 18, for days spent per month. (July, Aug, Sept)
Example data and sample output :
Client Check In Check Out
Majestica Inn 22-May-15 22-Jun-15 31 9 22
Twin Tree 29-May-15 30-Jun-15 32 2 31
Connaught Mews 1-Jun-15 31-Jul-15 60 29 31
Majestica Inn 18-Jul-15 18-Sep-15 62 13 31 18
Majestica Inn 18-Jul-15 18-Sep-15 62 13 31 18
I am new to Excel, please help.
if you can be flexible about the number of columns then you can use the below formulas to get the desired output.
Formula To Get The Days:
Remark: paste this formula in cell e2 and then drag & copy.
=IFERROR(IF(AND(MONTH(E$2&"-"&YEAR($B3))>=MONTH($B3),MONTH(E$2&"-"&YEAR($C3))<=MONTH($C3)),IF(MONTH(E$2&"-"&YEAR($B3))=MONTH($B3),DATEDIF($B3,EOMONTH($B3,0),"D"),IF(MONTH(E$2&"-"&YEAR($B3))=MONTH($C3),DATEDIF(DATE(YEAR($C3),MONTH($C3),1),$C3,"D")+1,DATEDIF(DATE(YEAR($C3),MONTH(E$2&"-"&YEAR($B3)),1),EOMONTH(DATE(YEAR($C3),MONTH(E$2&"-"&YEAR($B3)),1),0),"D")+1)),""),"Err")
Formula For Concatenating:
=IFERROR(DATEDIF($B2,$C2,"D")&IF(E2<>"",",","")&CONCATENATE(E2,IF(F2<>"",",",""),F2,IF(G2<>"",",",""),G2,IF(H2<>"",",",""),H2,IF(I2<>"",",",""),I2,IF(J2<>"",",",""),J2,IF(K2<>"",",",""),K2,IF(L2<>"",",",""),L2,IF(M2<>"",",",""),M2,IF(N2<>"",",",""),N2,IF(O2<>"",",",""),O2,IF(P2<>"",",",""),P2),"")
And If You Don't Want To Add any Columns Then Try This One......
Paste in Cell D2......
=IFERROR(SUBSTITUTE(DATEDIF($B2,$C2,"D")&","&IFERROR(IF(AND(MONTH("Jan"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Jan"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Jan"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Jan"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Jan"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Jan"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Feb"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Feb"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Feb"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Feb"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Feb"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Feb"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Mar"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Mar"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Mar"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Mar"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Mar"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Mar"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Apr"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Apr"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Apr"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Apr"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Apr"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Apr"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("May"&"-"&YEAR($B2))>=MONTH($B2),MONTH("May"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("May"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("May"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("May"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("May"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Jun"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Jun"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Jun"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Jun"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Jun"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Jun"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Jul"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Jul"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Jul"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Jul"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Jul"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Jul"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Aug"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Aug"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Aug"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Aug"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Aug"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Aug"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Sep"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Sep"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Sep"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Sep"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Sep"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Sep"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Oct"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Oct"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Oct"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Oct"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Oct"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Oct"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Nov"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Nov"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Nov"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Nov"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Nov"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Nov"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&IFERROR(IF(AND(MONTH("Dec"&"-"&YEAR($B2))>=MONTH($B2),MONTH("Dec"&"-"&YEAR($C2))<=MONTH($C2)),IF(MONTH("Dec"&"-"&YEAR($B2))=MONTH($B2),DATEDIF($B2,EOMONTH($B2,0),"D"),IF(MONTH("Dec"&"-"&YEAR($B2))=MONTH($C2),DATEDIF(DATE(YEAR($C2),MONTH($C2),1),$C2,"D")+1,DATEDIF(DATE(YEAR($C2),MONTH("Dec"&"-"&YEAR($B2)),1),EOMONTH(DATE(YEAR($C2),MONTH("Dec"&"-"&YEAR($B2)),1),0),"D")+1))&",",""),"Err")&"0|",",0|",""),"")
Good Luck .............

Using SUMIFS to pull YTD sales data in excel

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.

PowerPivot fiter to slice data per hour, day or month

I have an Excel database file that contains the total passenger passes from a specific location. The total number of passenger passes is counted in a period of 2 minutes(e.g. 14:45:00 to 14:46:59). I have imported my database into PowerPivot and have also created relevant PivotTables and PivotCharts with some slicers to analyze them. How can I create a slicer which filters data in greater periods of time like hour, day or month?
You'll need to create a Date/time table which contains all hours in your data.
First you'll need to create a calculated column in your original data that has the date and the hour
Formula to use:
=DATE(YEAR([Original Date]),MONTH([Original Date]),DAY([Original Date]))+HOUR([Original Date])/24
Result in your original data table
Original Date Calculated_DateHour
02/15/2015 14:15 02/15/2015 14:00
02/15/2015 16:25 02/15/2015 16:00
Now, in Excel create a Master Date table with unique date/time for all data
[DateTable]
Master_DateHour Year Month Day Hour
02/15/2015 13:00 2015 2 15 13
02/15/2015 14:00 2015 2 15 14
02/15/2015 15:00 2015 2 15 15
02/15/2015 16:00 2015 2 15 16
02/15/2015 17:00 2015 2 15 17
{...}
03/17/2015 02:00 2015 3 17 2
Next you'll create a relationship between the DateTable[Master_DateHour] (lookup table) and Data[Calculated_DateHour].
Now you should be able to slice based on the Year/Month/Day/Hour as you see fit.
Additionally, you could create a hierarchy in the [DateTable] to give you more control over the presentation of Year/Month/Day/Hour.

List all the corresponding numbers which fall within a month

I have a table which looks something like this
Month Item Haul
June Gravel 23
July Asphalt 45
June Asphalt 5
June Asphalt 7
September Asphalt 26
October Gravel 17
June Asphalt 21
September Gravel 25
I want to create a function that will list all of the different "Asphalt" hauls which happen within a given month in another sheet so that I can calculate the tonnages of each haul. The result should look something like this
June
5
7
21
Is this even possible?
With a PivotTable (Month for ROWS , Item for COLUMNS and Haul for Σ VALUES) you can set Σ VALUES to calculate the average for you and if you want the detail for Asphalt and June just double click on that row/column intersect. The drill down will automatically open in another sheet and the PT will default to a separate sheet unless you choose otherwise.

Resources