Thursday, June 16, 2016

How to Calculate Workdays per Month

We need to calculate the workdays per each month in list.

Solution
To calculate workdays per month, we will use the EOMONTH function together with the NETWORKDAYS function. In the example shown, the formula in B5 is:

=NETWORKDAYS(A5,EOMONTH(A5,0),holidays)


Explanation
The values in the Month column (A) are actual dates, formatted with the custom number format "mmm". For example, A13 contains September 1, 2016, but displays only "Sep".

The formula is based on the NETWORKDAYS function, which returns the number of working days between a start date and end date, taking into account holidays (if provided).

The syntax of the function is:
NETWORKDAYS( start_date, end_date, [holidays] ) where:
start_date - The start date, from which to count the number of workdays.
end_date - The end date, to count the number of workdays up to.
[holidays] - An optional argument, which specifies an array of dates (in addition to weekends) that are not to be counted as working days.

For each month, the start date comes from column B and the end date is calculated with the EOMONTH function like so: EOMONTH(A5,0) which takes a date and returns the last day of a month (for the 2nd argument we use zero to stay in the same month).

A list of holidays is the 3rd argument to NETWORKDAYS (the named range holidays (D5:D10)).

If we need take into account custom weekends (i.e. weekends are Friday and Saturday, Sunday or Monday only etc.) we'll need to switch to the NETWORKDAYS.INTL function.

Common Errors of NETWORKDAYS Function is
#VALUE!    -       Occurs if any of the supplied arguments are not valid dates.

How to Find the Last Day of a Month

I want to calculate the date at the end of each month.


Solution



Explanation

To calculate the date at the end of the current month, we will use the following formula:        =EOMONTH(TODAY(),0)

To calculate the date at the end of next month, we will use the following formula:        =EOMONTH(TODAY(),1)

To calculate the date at the end of each month (shown in column A) we will use following formula:= =EOMONTH(DATE($E$1,A2,1),0)

***********************************************************

The TODAY() function returns today’s date. This function has no argument.

The DATE function converts a supplied year, month and day into an Excel date.
The syntax DATE function is: DATE( year, month, day ) where the year, month and day arguments are integers representing the year, month and day of the required date.

The EOMONTH function returns the last day of the month that is a specified number of months before or after an initial supplied start date.
The syntax of the function is: EOMONTH( start date, months ) where
start date - The initial date.
months     - The number of months (positive or negative) to add to the
                start date, before returning the last day of the resulting month.

Monday, June 13, 2016

Calculating the Number of Hours per Month

I want to create the list of hours for each month in current year.
And second formula - taking into account the summer / winter time, i.e. subtract one hour in March and add one hour in September.

Solution

We will use DAY, EOMONTH, and DATE functions as shown in the following formula:

=DAY(EOMONTH(DATE($E$1,A2,1),0))*24-(A2=3)+(A2=9)



Explanation

DATE function returns the date of the first day of the month specified in cell A2, for the year 2016.
EOMONTH function returns the last day of the month per that date (the month specified in cell A2).
DAY function returns the number of days in the month entered in cell A2 and then multiplied by 24 to calculate the total number of hours for the month in cell A2.

The expression A2=3 returns "1" (TRUE) if the month number in cell A2 equals 3 (March) and "0" (FALSE) if it doesn’t. Similarly, the expression A2=9 returns "1" (TRUE) if the month number in cell A2 equals 9 (September) and "0" (FALSE) if it isn’t.

Thursday, June 9, 2016

How to Count Vacation days

Problem - Counting Vacation within a Specified Time Period

Below in column A there are dates when an employee was absent.
Letter V in column B indicates Vacation, PH – Public Holiday, T - Travel.
I want to count the number of vacation days during the last 180 days.

Solution

We should use SUMPRODUCT function in the following formula:

=SUMPRODUCT(((TODAY()-A2:A23)<=180)*(B2:B23="V"))



Explanation

TODAY function returns today’s date.

The expression [TODAY()-A2:A23] returns an Array consisting of the difference between today’s date and each date in column A (cells A2:A23), each value (the number of days between today’s date and a particular date in column A) in that Array, representing, is compared with 180 and returns "1" (TRUE) for every number in the Array that is smaller than or equal to 180, and "0" (FALSE) for every number that isn’t.

The expression [B2:B23=”V”] returns an additional Array consisting of "1" (TRUE) for every value in column B (cells B2:B23) that matches the absence type ("V") and "0" (FALSE) for every value that doesn’t:

The result represents the number of vacation days during the last 180 days.

Wednesday, June 8, 2016

How to sort birthdays by month (2 solutions)

Problem – How to sort birthdays by month (2 solutions)

I have the list of employees and their birthdays.
This list should be sorted by month, which is not possible with Excel’s built-in function.

Solution 1 (using MONTH and DAY functions)
         1.     In cells A2:B14 there is a list of employees and their birthdays.
     2.    Select cells C2:C14 and type the following formula:
=MONTH(B2)*100+DAY(B2).
     3.    Press <Ctrl+Enter>.
     4.    Sort your data on this column.
     5.    Format the column as General to display serial values rather than dates.

Solution 2 (using TEXT function)
1.     Insert new column C.
2.    Select cells D2:D14 and type the following formula:
=TEXT(B2,"MMDD") + 0
3.    Press <Ctrl+Enter>.
4.    Sort your data on this column.
5.    Format the column as General to display serial values rather than dates.



Tuesday, June 7, 2016

How to Calculate Work Days

Problem: Each employee in our company should pass the probation period (30 work days). How to calculate the end of this period?
Solution & Explanation:
To solve this problem we can use WORKDAY or WORKDAY.INTL functions. Just need to specify a start date, number of work days (30) and list of holidays.
1. Enter the holidays for this year (this list in E2:E7).
2. Enter the formula =WORKDAY(B2,$G$2,$E$2:$E$7)in cell C2. Please note that the argument containing the holidays and days of trial should be an absolute reference with dollar signs.
3. Format the cell C2 formula as a date.
4. Copy the formula down for all employees (see figure below).



Starting from Excel 2010 you can use WORKDAY.INTL function.
WORKDAY.INTL figures out a date that represents the "nearest" working day N days in the past or future. Use a positive number as days for future dates and a negative number for past dates. This function is more robust than the WORKDAY function because it lets you customize which days of the week are considered weekends (for example only Sunday or Friday).
Possible string values for the [weekend] argument consist of a series of seven 0's and 1's which represent the seven weekdays, starting from Monday. Each 1 denotes a day that should be counted as a weekend and each 0 represents a working day. For example, above formula can write like
0001100
-
denotes Thursdays and Fridays counted as weekend days
0000111
-
denotes Fridays, Saturdays and Sundays counted as weekend days.
 The string "1111111" is not valid.

Thursday, February 25, 2016

How to use INDEX & MATCH in Excel

In order to do a vertical lookup in Excel many users usually use VLOOKUP function. It’s understandable because VLOOKUP means Vertical Lookup J. And if you are offered to use INDEX MATCH functions instead of VLOOKUP you can ask "What do I need that for?". The point is that VLOOKUP is not the only lookup formula available in Excel, and its limitations to prevent you from getting the desired result in many situations. Excel's INDEX MATCH is more flexible and has certain features that make it superior to VLOOKUP in many respects.
Initially we consider INDEX & MATCH functions separately to understand how they work and then we’ll use them together to understand their key strengths. We will find examples that will help you easily solve complex tasks. Another benefit of using of INDEX & MATCH functions is that instead of just a vertical lookup, INDEX MATCH allows you to perform a matrix lookup, or “two-way lookup”. This combination formula may initially seem complex (because of its three individual formulas), but after you understand how they work, using of them will help you in many situations.

The INDEX function has the following arguments:
array:                  A range
      row_num:          A row number within the array argument
    column_num:    A column number within the array argument

If both row_num and column_num parameters are used, the INDEX function returns the value in the cell at the intersection of the specified row and column. For example, looking at the table below in the range A5:E55 we can use INDEX to return the capital of California with a formula as follows: =INDEX(A5:E55,6,2)

The result returned is Sacramento.
On its own the INDEX function is pretty inflexible because you have to hard key the row and column number, and that’s why it works better with the MATCH function.

The MATCH function has three arguments:

  1. lookup_value: The value (that you want to match in lookup_array).
If match_type is 0 and the lookup_value is text, this argument can include the wildcard characters * and ?.
  1. lookup_array: The range (that you want to search). This should be a one-column or one row range.
  2. [match_type]: An integer (–1, 0, or 1) that specifies how the match is determined.
     1 - find the largest value less than or equal to lookup_value
             (the list must be in ascending order)
     0 - find the first value exactly equal to lookup_value. Lookup_array
             (the list can be in any order)
    -1 -- find the smallest value greater than or equal to lookup_value.
             (the list must be in descending order)
    Note: If match_type is omitted, it is assumed to be 1.

Now we know the basics of these two functions, and start to use MATCH and
INDEX together. Below is the syntax for using this formula combination.
= INDEX ( array , MATCH ( lookup_value , lookup_array , 0 ) , MATCH (lookup_value , lookup_array , 0 ) )

And now, let us apply this formula in practice. Below, there is a list of the most populated counties in the world. Suppose, we want to know the number of population in the Japan in the year 2008:

OK, let's start on the formula. It’s a good practice to create a complex Excel formula with one or several nested functions. So let’s write each individual function first. Start by writing two MATCH functions that will return the row and column numbers for your INDEX function.

        Vertical match - you search through column B, (cells B3 to B12), for the value in cell H2 ("Japan"): MATCH($H$2,$B$3:$B$12,0).
This MATCH formula returns 10 because "Japan" is the 10th item in range $B$3:$B$12

Horizontal match - you search for the value in cell H3 ("2008") in row 2,
MATCH($H$3,$A$2:$E$2,0).

Now, put the above formulas inside the INDEX function:
=INDEX($A$3:$E$12, MATCH($H$2,$B$3:$B$12,0), MATCH($H$3,$A$2:$E$2,0)) and the result will  be 128.

 If we replace the MATCH functions with the returned numbers, the formula is much easier to understand: = INDEX($A$3:$E$12, 4, 10, 0))
Meaning, it returns a value at the intersection of the 4th row and 10th column in range A3:E12, which is the value in cell D12.

That's all!