How to calculate no of days spent per month from the data in MS Excel? - 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 .............

Related

Excel add hours to date excluding weekends and holidays

I would like to add hours on a start date and skip weekends and holidays in an Excel file.
The hours would be 24, 36 and 48.
So if the start date and time are 4 Mar 2019, 13:42, the end date and time should be :
24 hours: 5 Mar 2019, 13:42
36 hours: 6 Mar 2019, 01:42
48 hours: 6 Mar, 2019, 13:42
I am now using this formula:
=WORKDAY(E2,G2/24,Holidays!$A$2:$A$18)+MOD(E2,1)
E2 is the start date and time in mm/dd/yy hh:mm format, G2 is the number of hours, Holidays!$A$2:$A$18 is the range of holiday.
This formula works totally fine for 24 hours and 48 hours, however, it is not working for 36 hours. It would be much appreciated if someone would help me to solve this problem.
Construct a simple date from addition and then convert it to the workday.
=WORKDAY(A2+B2/24-1, 1, Holidays!$A$2:$A$18)+MOD(A2+B2/24, 1)

Find a customer usage for a given period of time

I have to bill a customer based on monthly usage however I'm only provided with a date range and total usage. I need to calculate the average daily usage, then calculate the number of days in each for the bill period, then multiply the days in month by the average to get the number of 'x' to bill the customer.
For example. I have two customers below and each has a different bill period and usage.
I'm given the data in Excel below. I'm struggling to build a formula that will give me A) the number of days in each month, B) the average use per day, C) the total amount used in each month. See the example below with how I calculate by hand.
Cell A1 Cell A2 Cell A3
9/5/2017 10/4/2017 83
Example:
Billing Period
Cust #1: 9/4/2017-10/4/2017 and usage is 85
Cust #2: 9/11/2017-10/11/2017 and usage is 1065
Cust #1
Sept Days is 27
Oct Days is 4
total days is 31
Ave use per day 2.7 (85 divided by 31)
Answer:
**Sept Usage is 74 Oct Usage is 11**
Cust #1
Sept Days is 20
Oct Days is 11
total days is 31
Ave use per day 34.35 (1065 divided by 31)
Answer:
**Sept Usage is 687 Oct Usage is 378**

Look up Cell data based on Month header in table

i'm trying to create a small spreadsheet for data verification.
Below i have created two tables Table 1 and Table 2.
What i am trying to find is a simple =Index Match or similar to check for Current month then copy that value to respective Group row under verification.
Problem is that the months are a header row and i have no idea how to check a header row for correct month then output the values in the cells below it to each corresponding group in the output list.
So to put it in programming terms this is what im looking for
If A2=Table2[Header] then c8=C4 else table[header] + step right
A2 contains todays Date (=today()) and Header has the shorten Month names as Jan Feb Mar and so on.
Something similar as above, i don't know if i'm making it harder for me then it really should be. I'm working with Excel 2013.
Output list
Group Input Verification Differance
G1 120 123 =Sum([#[Input]]-[#[Verification])
G2 76 110 =Sum([#[Input]]-[#[Verification])
G3 110 90 =Sum([#[Input]]-[#[Verification])
G4 34 53 =Sum([#[Input]]-[#[Verification])
Data list
Group Year Jan Feb Mar Apr
G1 2017 123 95 80
G2 2017 110 85 75
G3 2017 90 80 70
G4 2017 53 53 46
Regards
Johan
You would use a second match to find the correct column:
=INDEX(DataList,MATCH([#Group],DataList[Group],0),MATCH(TEXT($A$1,"mmm"),DataList[#Headers],0))

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.

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

Resources