List all the corresponding numbers which fall within a month - excel

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.

Related

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

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.

Excel: Calculation with different beginning dates

I have a long time-series of monthly returns for the S&P500. I would like to calculate the 3-month return, for a subset of dates?
For example, I would like to calculate the 3-month return for the following
A B C
Month Year 3-Month Return
Jan 1929
Dec 1948
July 1981
I have monthly return data like:
A B C
Month Year Monthly Return
Jan 1929 0.102
Feb 1929 0.072
Mar 1929 -0.231
....
....
Dec 2019 0.157
So the first calculation would be something like (1+0.102)(1+0.072)(1-0.231)-1. I can do this manually but have many calculations, unfortunately.
to find the match, you need a unique column, so combine A & B to another column, so that the month+year combination is unique, then use that combination to find the values.
Suppose you have data in this form:
The formula for match index is =match(P3,U$3:U$13,0) and that for your 3 monthly return is =(1+index(V$3:V$13,Q3))*(1+index(V$3:V$13,Q3+1))*(1+index(V$3:V$13,Q3+2))-1
You can put the match index inside the formula in C column to avoid the column, but you'd have to put it 3 times. you can also use different combination for combined date, like the actual date format of mm/yyyy, it'll still work.

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.

Excel: Value from one cell based on max value with multiple criteria in other column

I am trying to get value in column 8, based on MAX value (column Range4) with multiple criteria (Range1, Range2, Range3), but excel gives me an error "#N/A". Where is the mistake?
VLOOKUP(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));Range5;8;FALSE)
The part
{MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))))}
works right alone (it gives me the right value), but not inside the VLOOKUP function.
Thanks!
Sample data set for testing:
First_day Last_day Week_Num Week_Range Month Year Rank_name Rank_value
01/04/2013 07/04/2013 14 1-7 april april 2013 Alexa 10122
08/04/2013 14/04/2013 15 8-14 april april 2013 Alexa 9670
15/04/2013 21/04/2013 16 15-21 april april 2013 Alexa 9130
22/04/2013 28/04/2013 17 22-28 april april 2013 Alexa 8340
29/04/2013 05/05/2013 18 29-5 april april 2013 Alexa 7543
31/03/2014 06/04/2014 14 31-06 april april 2014 Alexa 11428
07/04/2014 13/04/2014 15 07-13 april april 2014 Alexa 7159
14/04/2014 20/04/2014 16 14-20 april april 2014 Alexa 7027
21/04/2014 27/04/2014 17 21-27 april april 2014 Alexa 6675
28/04/2014 04/05/2014 18 28-04 april april 2014 Alexa 5379
Equivalence between ranges and columns:
Range1 = Column "Year"
Range2 = Column "Month"
Range3 = Column "Rank_name"
Range4 = Column "Week_Num"
Range5 = Column "Rank_value"
Please try:
=INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));Range4;0))
with Control+Shift+Enter.
The problem with the existing formula (from pnuts, Jun 10 2014) is this:
The formula first narrows the list down by the nested if's, and then picks the maximum Week_Num from those rows that match your criteria. But having located that maximum, the MATCH function then ignores the criteria (they were only used to find the max from Range4). If you have other rows (even though they don't match the criteria) that have the same Week_Num, MATCH will locate the first row out of the whole list that has the same Week_Num in Range4. One solution is to add the same criteria to the MATCH's "lookup_array" that were used in the "lookup_value".
=INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4)));0))
Again, using Control-Shift-Enter.
I think I entered the above formula correctly, but I didn't build a sheet to test it, so...
Also, be aware, this formula still has a problem in the case where no rows in the list meet the criteria. In that case you get an error. The solution to that is to add an IFERROR at the front of the whole thing.
=IFERROR(INDEX(Range8;MATCH(MAX(IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4))));IF(Range1=2013;IF(Range2="april";IF(Range3="Alexa";Range4)));0)),"")

Resources