Using SUMIFS to pull YTD sales data in excel - 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.

Related

Excel automatically charting for concrete range of data

Excel masters, I need help about charting in excel. I have a table with data ("WEEK number", "date of start", "some data") and chart! the problem is: I need when I add new week data the chart should automatically update but I need to see only 53 weeks. For example: if I add week 30 I need to see data on the chart from week 30 (2018) to week 30 (2019)
Thank you for your help in advance
Week # Start Date Data
20 05-13-2018 21,866
21 05-20-2018 20,317
22 05-27-2018 18,078
23 06-03-2018 19,254
24 06-10-2018 17,990
25 06-17-2018 19,589
26 06-24-2018 22,346
27 07-01-2018 18,985
28 07-08-2018 18,482
29 07-15-2018 17,493
30 07-22-2018 21,217
31 07-29-2018 16,205
32 08-05-2018 16,534
33 08-12-2018 16,694
34 08-19-2018 18,190
35 08-26-2018 20,559
36 09-02-2018 24,503
37 09-09-2018 26,074
38 09-16-2018 24,092
39 09-23-2018 33,828
40 09-30-2018 28,979
41 10-07-2018 28,493
42 10-14-2018 30,634
43 10-21-2018 29,473
44 10-28-2018 28,202
45 11-04-2018 30,088
46 11-11-2018 36,070
47 11-18-2018 36,689
48 11-25-2018 35,509
49 12-02-2018 27,794
50 12-09-2018 27,802
51 12-16-2018 16,521
52 12-23-2018 13,786
1 12-31-2018 18,271
2 01-07-2019 27,336
3 01-14-2019 29,837
4 01-21-2019 31,464
5 01-28-2019 31,395
6 02-04-2019 31,383
7 02-11-2019 28,152
8 02-18-2019 30,795
9 02-25-2019 25,183
10 03-04-2019 28,344
11 03-11-2019 38,064
12 03-18-2019 36,815
13 03-25-2019 36,741
14 04-01-2019 35,849
15 04-08-2019 35,199
16 04-15-2019 28,407
17 04-22-2019 16,427
18 04-29-2019 29,678
19 05-06-2019 28,270
20 05-13-2019 24,046
21 05-20-2019 21,191
22 05-27-2019 21,480
23 06-03-2019 23,919
24 06-10-2019 20,532
25 06-17-2019 20,575
26 06-24-2019 19,111
27 07-01-2019 19,279
28 07-08-2019 22,265
29 07-15-2019 5,979
You can use defined names to automatically update a chart range in Excel.
You can refer to any array/range by a name in excel. There are formulas to find the specific array/range and we call them Array Formulas. One of the most common array formula is OFFSET. If you are not familiar with this formula, please google some tutorials online before continue.
In your example, let's presume Week # is in Column A, Start Date is in Column B, and Data is in Column C, and the name of the worksheet is SheetName.
In order to dynamically look up a 53-Week range in Column A, B and C using OFFSET formula, you need to find the starting point (i.e. the cell in each column corresponds to the first week of the 53-week range) .
For instance, if your latest Week # is Week #29 in Cell A63, the starting point would be Week #29 in Cell A11. One way of finding the latest week # is to find the corresponding maximum/latest date in the Start Date column, and use MATCH formula to find the row number. Such logic is translated into the following formulas:
Start Point in Column A (the Week # column) ="A"&MATCH(MAX(B:B),B:B,0)-52
Start Point in Column B (the Start Date column) ="B"&MATCH(MAX(B:B),B:B,0)-52
Start Point in Column C (the Data column) ="C"&MATCH(MAX(B:B),B:B,0)-52
Then you can find the 53-Week range in each column by referencing the relevant starting point in the OFFSET formula. Please note you need to press CSE Ctrl+Shift+Enter upon finishing entering each array formula to make it work.
For Column A (the Week # column) =OFFSET(INDIRECT("SheetName!A"&MATCH(MAX(SheetName!$B:$B),SheetName!$B:$B,0)-52),,,53)
For Column B (the Start Date column) =OFFSET(INDIRECT("SheetName!B"&MATCH(MAX(SheetName!$B:$B),SheetName!$B:$B,0)-52),,,53)
For Column C (the Data column) =OFFSET(INDIRECT("SheetName!C"&MATCH(MAX(SheetName!$B:$B),SheetName!$B:$B,0)-52),,,53)
The next step is to create three names for the above ranges. Press Ctrl+F3 to open the Name Manager in excel, and manually create the names and copy and paste the above formulas in the 'Refers to:' field.
Then you can create a chart from the existing data, and replace the hard-coded series values with the range names to make it dynamic as shown below:
Click anywhere within the chart, then you will see the Chart Design tab shown on top of the the ribbon of your excel. Go to Select Data and Edit the Data and Date value as shown below:
I have created a sample bar chart below showing the data for the most recent 53 weeks. Please note I have added 5 weeks' of new data to test the result, and I have put the Week # as the data label for the bar chart instead of the actual dollar value.
Lastly, you can refer to the following article for more clarifications.
How to use defined names to automatically update a chart range in Excel

Sort Data by date with VBA

I will try to keep this as simple as possible and cause no confusion.
I have over 35,000 rows and 15 columns of data but I am going to provide a very simple case of what I am trying to do.
Basically, I want to sort my dates in column A in ascending order, but then also have the data corresponding to a date sorted to "follow" it to its new row location. I want this to be done using VBA code.
Simple Case
Raw Data
Column A Column B
Jan 5 15
Jan 3 45
Jan 1 7
Jan 10 12
Jan 7 30
Expected Sorted Data
Column A Column B
Jan 1 7
Jan 3 45
Jan 5 15
Jan 7 30
Jan 10 12
I have looked all over and can not find a good way to do this. Any and all help will be greatly appreciated. Thanks!

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 .............

Dynamic Chart in Excel

Country January February March April May June July
USA 34 34 45 34 23
China 45 56 34 23 12
Japan 34 54 23 23 24
How can I show the last 3 months in the chart every time I update the data. Considering that column "Country" is fixed. Any workaround or easy formula to use in my "data selection" when creating a chart.
This should work perfectly.
1. Re-arramge the data
Country USA China Japan
January 34 45 34
February 34 56 54
March 45 34 23
April 34 23 23
May 23 12 24
Like so, it will be easier to work with. Here we assume the data starts at cell A1.
2. Create names in Name Manager (ctr+F3 to open)
name: refers to:
months =OFFSET(Sheet1!$A$1,COUNTA(Sheet1!$A:$A)-1,0,-MIN(length,COUNTA(Sheet1!$A:$A)-1),1)
length 3
usa =OFFSET(months,0,1)
china =OFFSET(months,0,2)
japan =OFFSET(months,0,3)
In length, you note the desired time-period you wish to show (in your case 3 months); this can also be done with a cell reference and a COUNTA if you wish to make it dynamic and account for all the new data.
3. Create the chart
Click on blank cell and open the desired chart (I have done it with a
2-D Clustered Column). //Note that the chart should be blank.
Right-click on Select Data and click Add for Legend Entries
(Series). Here for Series Name, select whatever is desired (in your case USA China Japan). For Series Value add =Sheet1!usa
Do this two more times for =Sheet1!china & =Sheet1!japan
Finally for the Axis Label add =Sheet1!months
Click though OK and you should be all set!
Make sure you check out how the offset function works here: https://support.office.com/en-za/article/OFFSET-function-c8de19ae-dd79-4b9b-a14e-b4d906d11b66

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