Is this Time between Working Hours

How can we check whether the giv­en time is between the work­ing hours or not?

Is this Time between Work­ing Hours 

In our case, work starts at 9:30 AM, and ends at 5:30 PM. Our giv­en time, which is 6:47 isn’t between the work­ing ours. When we change it, we can see that the col­or changed into red and ‘No’ turned into ‘Yes’, which means that now the time is between the work­ing ours (Fig. 1)

Our given time is between the working hours
Fig. 1 Our giv­en time is between the work­ing hours

How­ev­er, when we go to ear­li­er hours we can see that the details changed (Fig. 2)

 Our given time isn't between the working hours
Fig. 2 Our giv­en time isn’t between the work­ing hours

How can we check our time? The sim­plest solu­tion is using the MEDIAN func­tion that returns the val­ue in the mid­dle. Since all our times are in one row, we can just select the range (Fig. 3)

=MEDIAN(B2:D2)

Selecting the whole range
Fig. 3 Select­ing the whole range

If our data is in sep­a­rate cells, we can just add those cells one by one (Fig. 4)

=MEDIAN(B2,C2,D2)

Selecting cells one by one
Fig. 4 Select­ing cells one by one

And just like that we receive the val­ue in the mid­dle. If this val­ue is equal to the giv­en time, it means it’s between the work­ing hours. What’s curi­ous about our medi­an is the fact that it won’t cross our thresh­olds, i.e. our start­ing time and fin­ish­ing time. It means that the small­est val­ue our MEDIAN func­tion can show is the start­ing hour, and the largest is the fin­ish­ing hour (Fig. 5)

The smallest value
Fig. 5 The small­est value

Now, we have to check whether our time is between the work­ing hours. We have to com­pare the func­tion to the giv­en time (Fig. 6)

=MEDIAN(B2,C2,D2)=B2

Comparing
Fig. 6 Comparing 

As we can see, our log­i­cal test returned FALSE (Fig. 7)

FALSE
Fig. 7 FALSE

If the log­i­cal test returns TRUE, it means that the giv­en time is between the work­ing ours (Fig. 8)

TRUE
Fig. 8 TRUE

The answers we have are log­i­cal. Let’s make them more human like by adding the IF func­tion to our MEDIAN log­i­cal test and some sim­ple text like ‘Yes’ and ‘No’ (Fig. 9)

=IF(MEDIAN(B2,C2,D2)=B2,“Yes”,“No”)

Adding the IF function
Fig. 9 Adding the IF function

We can see that we can check whether our giv­en time is between the work­ing ours or no (Fig. 10)

Human answer
Fig. 10 Human answer

https://www.youtube.com/watch?v=IVZIY6-78sc

Named ranges and statistics

Some­times, we need to make many sta­tis­ti­cal oper­a­tions and use many sta­tis­ti­cal func­tions in Excel. How can we do it?

Named ranges and statistics 

A fast and quick solu­tion is using name ranges. For exam­ple, we have the SUM func­tion that sums up all val­ues from Jan­u­ary (Fig. 1)

SUM function
Fig. 1 SUM function

How can we name ranges and use them for our advan­tage? Let’s start with a sim­ple exam­ple of the SUM func­tion. For the SUM func­tion, we have key­board short­cut which is Alt + =. This way Excel will put the sum for Jan­u­ary, which is a range form B2:B6 (Fig. 2)

=SUM(B2:B6)

Alt + = to put the sum
Fig. 2 Alt + = to put the sum

In the exam­ple above we had num­bers. How­ev­er, let’s go to anoth­er sheet where we have no num­bers. When we want to sum the num­bers from the pre­vi­ous sheet, it’s going to be a very tedious job, as we have to move between those two sheets and write prop­er val­ues. What’s more, the ref­er­ence we have while using val­ues form anoth­er sheet isn’t the eas­i­est to under­stand. What we can do is nam­ing the ranges. We just have to select a range in a col­umn and write a prop­er name in the Name Box (Fig. 3).

Naming the range
Fig. 3 Nam­ing the range

Now, when we are using the Alt + = short­cut under our val­ues, Excel will auto­mat­i­cal­ly refer to the Jan­u­ary range, which is B2:B6 (Fig. 4)

=SUM(Jan­u­ary)

Automatic reference
Fig. 4 Auto­mat­ic reference

As we know, Excel remem­bers names. It means that we can use the name in cal­cu­la­tion on a dif­fer­ent sheet. When I start writ­ing “ja” in anoth­er sheet, Excel will sug­gest the range name (Fig. 5). I can just accept it and sum the val­ues from January. 

Excel suggested the range name
Fig. 5 Excel sug­gest­ed the range name

As we can see, nam­ing ranges makes our work faster. We can also name a big­ger group of columns at one time. Just select the group you want. What’s impor­tant, when you’re select­ing your data, you have to select the top rows, and then the num­bers beneath them. Then, go to the For­mu­las tab, click on the Cre­ate from Selec­tion com­mand and select the Top Row check­box in the win­dow that appeared (Fig. 6)

Creating names from selection
Fig. 6 Cre­at­ing names from selection

Now, after we named our ranges, we can see that the Feb­ru­ary range is named Feb­ru­ary, the March range is named March and so on. When we move to anoth­er sheet, we can use those names (Fig. 7)

Excel is suggesting the new names
Fig. 7 Excel is sug­gest­ing the new names

How­ev­er, we can go one step fur­ther using the ref­er­ence to names. I have Jan­u­ary in cell B1. But, when I refer to cell B1, Excel won’t sim­ply con­vert the text from cell B1 to a range because it just text. It means that our func­tion won’t add any­thing. First of all, we have to lock the rows (B$1), then add the INDIRECT func­tion to our cal­cu­la­tion. Now, the INDIRECT func­tion changes the text into a ref­er­ence to the prop­er range (Fig. 8)

=SUM(INDIRECT(B$1))

INDIRECT function
Fig. 8 INDIRECT function

Now, when I drag the for­mu­la to the right, I will have sums from each indi­vid­ual month (Fig. 9)

=SUM(INDIRECT(F$1))

Sum from individual months
Fig. 9 Sum from indi­vid­ual months

When I copy the for­mu­la one cell low­er, I’m just chang­ing SUM into AVERAGE (Fig. 11)

=AVERAGE(INDIRECT(B$1))

SUM into AVERAGE
Fig. 1 SUM into AVERAGE

After I drag it to the right, I have prop­er results. I do the same with the remain­ing rows (Fig. 12)

=MIN(INDIRECT(B$1))

Changing the remaining names
Fig. 12 Chang­ing the remain­ing names

This way, we can quick­ly add more sta­tis­ti­cal oper­a­tions for many months using prop­er name ranges and the INDIRECT function. 

https://www.youtube.com/watch?v=E9APUsy4y‑E

Cubic root, square root and nth root

Some­times, we need to cal­cu­late a cubic root, square root or an nth root of a num­ber. How can we do that?

Cubic root, square root and an nth root

First of all, we can use the SQRT func­tion to cal­cu­late a square root (Fig. 1)

=SQRT(A3)

SQRT function
Fig. 1 SQRT function

And here we have our results. There is also the POWER func­tion used for cal­cu­lat­ing the square root with the use of inverse num­bers. The num­ber for a square root is 1 divid­ed by 2 (1/2). (Fig. 2)

=POWER(A3,1/2)

POWER function
Fig. 2 POWER function

As we can see the results are the same. We can even use a sim­ple sym­bol of rais­ing a num­ber to a pow­er. In the case of a cubic root it will be the num­ber from cell A3 (2), then a caret (Shift + 6). Then, the reverse of a cubic, which is 1/3 writ­ten in a paren­the­sis (Fig. 3)

=A3^(1/3)

Cubic root
Fig. 3 Cubic root

And we have our cubic roots. In the case of the fourth root, we will use the same cal­cu­la­tion, which is a caret and, this time, 1/4 (Fig. 4)

=A3^(1/4)

Fourth root
Fig. 4 Fourth root

And we have our fourth root. In the case of the tenth root, I can even write this num­ber as 0.1 (Fig. 5)

=A3^0.1

Tenth root
Fig. 5 Tenth root

And, just like that we have our tenth root (Fig. 6)

Final results
Fig. 6 Final results

Depend­ing on the sit­u­a­tion, use the cal­cu­la­tion you under­stand the most. 

https://www.youtube.com/watch?v=tdz5fLm98aE

Population Pyramid Chart

Some­times, we need to insert a pop­u­la­tion pyra­mid in Excel or a chart com­par­ing two values. 

Pop­u­la­tion Pyra­mid Chart

One part of the chart is on the left, while the oth­er is on the right. In order to cre­ate some­thing like pop­u­la­tion pyra­mid we have to insert a prop­er chart. I’m using data from Poland as I’m an Excel lover from Poland. We have to have one part of neg­a­tive val­ues, which will go to the left side of the chart. If you want to do it, you have to write ‑1 in one cell, then copy it and select all val­ues where we want to change the sign, then use the Paste Spe­cial option (or use the Alt + Ctrl + V short­cut). In the Paste Spe­cial win­dow, select the Val­ues radio but­ton and the Mul­ti­ply radio but­ton in the Oper­a­tion sec­tion. It means that we will be mul­ti­ply­ing ‑1 by the select­ed val­ues (Fig. 1)

Paste Special window
Fig. 1 Paste Spe­cial window

Now, we have neg­a­tives and pos­i­tives, which is the left and the right side of our chart. We can insert the chart. Let’s select one cell and go to the Insert tab and find the Clus­tered Bar option (Fig. 2)

Clustered Bar option
Fig. 2 Clus­tered Bar option

The chart that appeared isn’t good enough for us. The first mod­i­fi­ca­tion we want to imple­ment is chang­ing the title. Let’s write ‘Pop­u­la­tion Pyra­mid’ (Fig. 3)

Chart Title change
Fig. 3 Chart Title change

I also want to mod­i­fy bars. Let’s click on them, then press Ctrl +1. For­mat Data Series win­dow will appear where we have to select 100% in the Series Over­lap sec­tion and set the Gap Width to 10% (Fig. 4)

Series Overlap and Gap Width options
Fig. 4 Series Over­lap and Gap Width options

Now, the bars are larg­er. The next thing is the Ver­ti­cal Axis. Click Ctrl + 1 short­cut and go to the Labels tab. Set the Label Posi­tion to Low which, in our case, is the left side. In the Spec­i­fy inter­val unit let’s leave 1 (Fig. 5) 

Label Position and Specify Interval Unit options
Fig. 5 Label Posi­tion and Spec­i­fy Inter­val Unit options

Now, the chart looks much bet­ter, but I don’t like the ver­ti­cal lines here. Let’s click it and press the Delete key (Fig. 6)

Vertical lines not needed
Fig. 6 Ver­ti­cal lines not needed

The next thing we want to change is the hor­i­zon­tal axis where we have per­son val­ues. It means that we don’t need any neg­a­tive val­ues. We have to select it, press Ctrl + 1, then in the For­mat Axis win­dow, we need to go to the Num­bers bar. In the For­mat Code bar, we need to repeat the per­cent code for the neg­a­tive val­ues. Let’s add a semi­colon, then write 0.00% with­out any minus sign. Then, we click on the Add but­ton (Fig. 7)

Format Code bar
Fig. 7 For­mat Code bar

Now, we have pos­i­tive val­ues on the left and on the right side of the chart. What I’m still miss­ing is Data Labels. We have to press the plus sign and select the Data Labels check­box (Fig. 8)

Adding Data Labels
Fig. 8 Adding Data Labels

We can see that the label font is too big. Let’s make it small­er by select­ing the labels and chang­ing the font size on the rib­bon (Fig. 9)

Changing the font size
Fig. 9 Chang­ing the font size

There is still one more thing we need to change. There are minus signs on the left side of the chart. So, let’s press the Ctrl + 1 short­cut and go to the For­mat Data Labels win­dow. We have to open the Num­ber tab and write the per­cent­age once again. We sep­a­rate the per­cent­ages with a semi­colon, so that the per­cent­age from the left side cor­re­sponds to the left part of the chart, and the right cor­re­sponds to the right part. Then, we press Add (Fig. 10)

Two percentages
Fig. 10 Two percentages

In the end, I want to change the posi­tion of the leg­end. Let’s select the leg­end and press Ctrl + 1. We can see many options con­cern­ing the posi­tion of the leg­end (Fig. 11)

Legend Positions
Fig. 11 Leg­end Positions

How­ev­er, I want to change the posi­tion man­u­al­ly. Let’s drag it to the right and change its size. We can also change the size of the bars. There are many more mod­i­fi­ca­tions that you can imple­ment. My Pop­u­la­tion Pyra­mid is fin­ished and looks as fol­lows (Fig. 12)

 Finished Population Pyramid
Fig. 12 Fin­ished Pop­u­la­tion Pyramid

https://www.youtube.com/watch?v=fRnzw4LV18c

Add degree sign (°C) to numbers

Some­times, we want to add a degree sign to num­bers. How can we do it? 

Add degree sign (°C) to numbers

Let’s say we want to show tem­per­a­ture in degrees Cel­sius or Fahren­heit. The first thing we want to do is insert­ing the cor­rect sign. We can either copy it from the inter­net or we can choose the Sym­bol com­mand from the Insert tab (Fig. 1). 

Adding a symbol
Fig. 1 Adding a symbol

In the Sym­bol win­dow that appears, we’re choos­ing the Latin‑1 Sub­set (1), then the Degree Sign, whose name we can see at the bot­tom of this win­dow. We click the Insert and Close but­tons (Fig. 2). 

Symbol window
Fig. 2 Sym­bol window

We can see the Degree Sign in cell D1. After adding C, we have the full sym­bol. Now, we can copy the sym­bol in the edit mode, then select all cells with num­bers to which we want to add the sign. Then, we press the Ctrl + 1 short­cut. In the For­mat Cells win­dow we’re choos­ing the Cus­tom Cat­e­go­ry, then we’re choos­ing 0 and we can paste the °C sign. In the Sam­ple bar we can pre­view what our final text will look like in the end. If we want to make sure that our text will be show as a text in the end, we can write it in dou­ble quotes. In this case, it’s a bul­let­proof solu­tion (Fig. 4). 

Format cells window
Fig. 4 For­mat cells window

And we have our signs cor­rect­ly insert­ed (Fig. 5). 

Final results
Fig. 5 Final results

https://www.youtube.com/watch?v=y751VP0yMbE

Merge Cells vs Center across selection

How can we cre­ate a head­line title that is in the Cen­ter Across Selec­tion mode?

Merge Cells vs Cen­ter across selection

In Excel, we have two solu­tions. We can select sales and use the Megre&Center com­mand from the Home tab (Fig. 1) 

Megre&Cente command
Fig. 1 Megre&Center command

Excel will merge cells into one cell and align it in the cen­ter (Fig. 2).

One, centered cell
Fig. 2 One, cen­tered cell

This solu­tion, how­ev­er, has got a small draw­back as it cre­at­ed one cell instead of many cells. When we try to select only one col­umn and go a bit too high, we end up in select­ing every col­umn (Fig. 3)

All columns are selected
Fig. 3 All columns are selected

But, when we go down again, we will select only one col­umn again, so it’s not a big prob­lem. Some­times, we want to move our data a bit to the right or left. When we try to copy our range, we can’t select only cell B1, which is a bit prob­lem­at­ic. After select­ing the whole range, we want to move it to the right. How­ev­er, there’s still a prob­lem. If we want to move the range only a bit to the left or right, we can­not do it (Fig. 4).

Merged cells cannot be moved only a bit
Fig. 4 Merged cells can­not be moved only a bit

We have to go far enough to the right to make Excel copy the merged cell (Fig. 5).

 Merged cells moved
Fig. 5 Merged cells moved

I want to show you one more solu­tion. Let’s des­e­lect the Megre&Center com­mand. Now that we have our range select­ed, we can press the Ctrl + 1 short­cut to go to the For­mat Cells win­dow. In the win­dow, we have to go to the Align­ment tab, then select the Cen­ter Across Selec­tion com­mand in the Hor­i­zon­tal area, and press OK (Fig. 6). 

Format Cells window
Fig. 6 For­mat Cells window

We can see that our select­ed cells have merged. But this time, when we try to select one whole col­umn, we can do it (Fig. 7).

Whole column selected
Fig. 7 Whole col­umn selected

You have to remem­ber that now the val­ue is locat­ed in cell A1. There’s noth­ing in B1, C1 and D1 cells. The val­ue was just cen­tered across selec­tion. Let’s now change the col­or­ing of the head­line title and try to move it a bit to the right (Fig. 8).

Moving the range
Fig. 8 Mov­ing the range

As we can see, it’s pos­si­ble (Fig. 9).

The whole range moved a bit
Fig. 9 The whole range moved a bit

When we have the cell in the Cen­ter Across Selec­tion mode, it’s also impor­tant that when we want to add some text to one of the cells, the Cen­ter Across Selec­tion option will work only on the cells that are not filled (Fig. 10)

Center Across Selection working only in cells A1, B1 and C1
Fig. 10 Cen­ter Across Selec­tion work­ing only in cells A1, B1 and C1

https://www.youtube.com/watch?v=9P4HxHSbpbA

Sum of top 3 values

How to cal­cu­late a sum or an aver­age of top 3 max­i­mal values?

Sum of top 3 values

In Lega­cy Excel, we can use the LARGE func­tion, in which we need to select the range for our cal­cu­la­tion. In the k argu­ment let’s write 1 (Fig. 1).

=LARGE($C$2:$C$33,1)

 LARGE function
Fig. 1 LARGE function

After enter­ing the func­tion, we have the largest val­ue (Fig. 2). 

The largest value
Fig. 2 The largest value

Now, we can copy the func­tion and add the sec­ond and the third largest val­ue (Fig. 3).

=LARGE($C$2:$C$33,1)+LARGE($C$2:$C$33,2)+LARGE($C$2:$C$33,3)

Adding more values
Fig. 3 Adding more values

This way we have the sum of 3 largest val­ues (Fig. 4). 

The sum of 3 largest values
Fig. 4 The sum of 3 largest values

This solu­tion, how­ev­er, is the least dynam­ic of all solu­tions we have. We can make this for­mu­la short­er by hard­cod­ing our val­ues. We have to write 1, 2 and 3 as an array (Fig. 5).

=LARGE($C$2:$C$33,{1;2;3})

The first, second and third value written as an array
Fig. 5 The first, sec­ond and third val­ue writ­ten as an array

This way Excel will return three largest val­ues. I’m using Dynam­ic Excel, so the results are spilled (Fig. 6).

Spilled results
Fig. 6 Spilled results

Now, that our val­ues have been hard-cod­ed, we can sum them by using the SUM func­tion. We can also use this func­tion to sum up aver­ages (Fig. 7). 

=SUM(LARGE($C$2:$C$33,{1;2;3}))

Summing up the largest values
Fig. 7 Sum­ming up the largest values

Our results (Fig. 8).

Results
Fig. 8 Results

This solu­tion, how­ev­er, is hard to mod­i­fy, so we can make it a bit more dynam­ic. We can use the ROW func­tion and select the first three rows from the sheet. This way our solu­tion is more dynam­ic (Fig. 9). 

=SUM(LARGE,($C$2:$C$33,ROW(A1:A3)))

A more dynamic solution
Fig. 9 A more dynam­ic solution

Results (Fig. 10). 

Results
Fig. 10 Results

But, in Lega­cy Excel, we should use the SUMPRODUCT func­tion instead of the SUM func­tion or use the Ctrl + Shift + Enter short­cut to put the for­mu­la into the cell (Fig. 11).

=SUMPRODUCT(LARGE,($C$2:$C$33,ROW(A1:A3)))

SUMPRODUCT function
Fig. 11 SUMPRODUCT function

And we have the result. In the sec­ond col­umn, in Dynam­ic Array Excel, we still need the SUM and LARGE func­tions, then the array which is the range we will look at. Then, we can use the SEQUENCE func­tion to cre­ate a sequence of prop­er num­bers, let’s take 3 (Fig. 12).

=SUM(LARGE($C$2:$C$33,SEQUENCE(3)))

Adding the SEQUENCE function
Fig. 12 Adding the SEQUENCE function

We have prop­er results (Fig. 13).

Results
Fig. 13 Results

This solu­tion is much more dynam­ic. Let’s change the num­ber into 5 (Fig. 14).

=SUM(LARGE($C$2:$C$33,SEQUENCE(5)))

3 changed into 5
Fig. 14 3 changed into 5

Here is the result (Fig. 15). 

Results
Fig. 15 Results

In Lega­cy Excel, we can also change one num­ber. Let’s change the num­ber of rows in the range from 3 to 5 (Fig. 16).

=SUMPRODUCT(LARGE($C$2:$C$33,ROW(A1:A5)))

A3 into A5
Fig. 16 A3 into A5

And we have the same result (Fig. 17).

Result
Fig. 17 Result

We have to remem­ber which ver­sion of Excel we have and which solu­tion we can use. 

https://www.youtube.com/watch?v=B2f4hvKBadk

Running Total in Pivot Table

Some­times, you need to cre­ate a run­ning total in piv­ot tables. How to do it properly?

Run­ning Total in Piv­ot Table

Let’s start with cre­at­ing a piv­ot table. Select one cell from our data and go to the Insert tab and select the Piv­ot Table com­mand. A Piv­ot table from table or range win­dow will appear, where we have our range. We need to select the Exist­ing work­sheet radio but­ton and write the loca­tion, which, in our case, will be cell F1. Let’s click the OK but­ton (Fig. 1).

Creating a pivot table
Fig. 1 Cre­at­ing a piv­ot table

And there we have it. In our piv­ot table we need to drag the Date to the Rows labels. 

Dragging the date
Fig. 2 Drag­ging the date

Now, depend­ing on the Excel ver­sion, we have an option of Group by dates. I’m going to group our date by months and years (Fig. 3).

Grouping
Fig. 3 Grouping 

We have our table. Now, I want to add Income so let’s press the Income check­box (Fig. 4). 

 Income checkbox
Fig. 4 Income checkbox

Now, I want to have the income and the run­ning total for the income, so let’s drag the Income two times to the Val­ues area. We can see that we have Sum of Income and Sum of Income 2, where we actu­al­ly want to have our run­ning total (Fig. 5). 

Income and Income 2
Fig. 5 Income and Income 2

Let’s right click any val­ue from Income 2, then select the Show Val­ues as and then the Run­ning Total In option (Fig. 6). 

Selecting the Running Total option
Fig. 6 Select­ing the Run­ning Total option

Now, we have to decide whether we want to base our run­ning total on Date or Years Field. Let’s take Date (Fig. 7).

 Date Field
Fig. 7 Date Field

Now, we can see that in the Income 2 col­umn we have big­ger num­bers. Let’s for­mat them by press­ing any cell in the col­umn and choos­ing the Num­ber For­mat option (Fig. 8). 

Number Format option
Fig. 8 Num­ber For­mat option

In the For­mat Cell win­dow, let’s choose the Cur­ren­cy cat­e­go­ry, in Dec­i­mal places let’s write 0 and press the OK but­ton. Let’s do the same in the Sum of Income col­umn (Fig. 9). 

 Format cell window
Fig. 9 For­mat cell window

Now, we can see that we are work­ing with mon­ey. In each month we have big­ger and big­ger num­bers which means that we have the run­ning total in this col­umn. We can change the name of Sum of Income 2 into Run­ning Total. Since we are using the Date Field as our ref­er­ence point, we have the run­ning total in 2020. In 2021 Excel counts from the start, which means that we have the run­ning total only for 2021. The same is with 2022. If we change the Date field into the Years field in the Show Val­ues as (Run­ning Total) win­dow, we will have the same val­ue in the first year and in the Sum of Income col­umn (Fig. 10).

Years
Fig. 10 Years

How­ev­er, in the next year, we have the the sum from Jan­u­ary 2021 and Jan­u­ary 2020. In Feb­ru­ary, we have the sum from Feb­ru­ary 2021 and 2020. In 2022, we have sums from three Feb­ru­ar­ies (Fig. 11).

Sums from three Ferbuaries
Fig. 11 Sums from three Ferbuaries

Let’s drag Man­ag­er into the columns head­er (Fig. 12).

Dragging Manager into headers
Fig. 12 Drag­ging Man­ag­er into headers

By doing so, we can show val­ue from the Man­ager’s per­spec­tive, which means a hor­i­zon­tal view. 

Horizontal view
Fig. 13 Hor­i­zon­tal view

How­ev­er, this type of data isn’t a prop­er one to show it this way, so let’s get back by press­ing Ctrl + Z two times and see that we can also cre­ate a per­cent run­ning total by going to the % Run­ning Total In option and choose the Date Field (Fig. 14). 

Percentage Running Total
Fig. 14 Per­cent­age Run­ning Total

Now, we can see the val­ues as per­cent­age (Fig. 15). 

Results
Fig. 15 Results

https://www.youtube.com/watch?v=ikou6toX11g

Running Total

Some­times you need to cre­ate a run­ning total.

Run­ning Total 

The most ver­sa­tile solu­tion I know is using the SUM func­tion and a dynam­ic range which in our case is $B$2:B2. How­ev­er, the most impor­tant fact is that we have to lock (F4 key) the first part of this range (Fig. 1).

=SUM($B$2:B2)

SUM function
Fig. 1 SUM function

When we copy our for­mu­la down, we can see that the first part of the range will always refer to cell B2, but the sec­ond one will go down as we drag the for­mu­la. This way, we have a range that expands as we go down. It’s the most ver­sa­tile solu­tion (Fig. 2). 

=SUM($B$2:B4)

An expanding range
Fig. 2 An expand­ing range

This solu­tion has prob­lems with Excel tables. When we sum from F2 to F2 cells and press F4 key to lock it, every­thing looks fine. How­ev­er, when we add new data to our table, the last cell will expand because it refers to the whole col­umn July -> August (Fig. 3). 

 Adding a new value
Fig. 3 Adding a new value

In this case, we have to mod­i­fy our range. Instead of cell F2 we can use the table nomen­cla­ture. When we click cell F2, Excel will refer to this table row, where @ means this table row, and Income means the col­umn we are refer­ring to (Fig. 4). 

=SUM($F$2:[@Income])

 Range modification
Fig. 4 Range modification

We have to over­write all cells (Fig. 5). 

Overwriting cells
Fig. 5 Over­writ­ing cells

This way we got prop­er results. We can check if it works prop­er­ly by adding some new rows. After we added two rows, the results are still cor­rect (Fig. 6).

Correct formula operation
Fig. 6 Cor­rect for­mu­la operation

The only draw­back of this for­mu­la is that we won’t see the whole range because Excel won’t select the whole range. The­o­ret­i­cal­ly, the last cell should include the whole col­umn but Excel selects only the first and the last row (Fig. 7).

=SUM($F$2:[@Income])

The formula in the last cell
Fig. 7 The for­mu­la in the last cell

We won’t see it, but Excel will. We have to remem­ber that Excel will cre­ate a prop­er ref­er­ence and we can cre­ate a prop­er run­ning total, even in Excel tables. 

https://www.youtube.com/watch?v=djsC6ybbuWk

Median with condition

If you want to cal­cu­late a medi­an val­ue with a con­di­tion, you can­not use a sim­ple MEDIAN func­tion because it needs only num­bers. We have to use anoth­er func­tion that will reduce the num­ber of wages we look at. 

Medi­an with condition

Typ­i­cal­ly, when we want to add a con­di­tion to anoth­er func­tion we can use the IF func­tion and make a log­i­cal test. In our case, the log­i­cal test will be sim­ple. We just have to check each cell in the Depart­ment col­umn whether it’s equal to the name of the Depart­ment we look at now. Since we are com­par­ing a sin­gle cell to a whole range, Excel will check every sin­gle cell in a giv­en range (Fig. 1). 

Comparing a single cell to a range of cells
Fig. 1 Com­par­ing a sin­gle cell to a range of cells

If a cell in the range is equal to the tar­get cell, we want the func­tion to return prop­er wages, i.e. the wages from the same row. If the log­i­cal test result is FALSE, we want to have some­thing that the MEDIAN func­tion will ignore which, in most cas­es, is an emp­ty text string. How­ev­er, I want to show you that the IF func­tion real­ly returns some­thing so let’s write “no” (Fig. 2).

=IF($B$2:$B$13=E2,$C$2:$C$13,“no”)

IF function
Fig. 2 IF function

We can see that Dynam­ic Array Excel spilled the results and we have wages only for the depart­ments we chose. For oth­er depart­ments we have ‘no’. Now, we can put this func­tion into the MEDIAN func­tion (Fig. 3).

=MEDIAN(IF($B$2:$B$13=E2,$C$2:$C$13,“no”))

MEDIAN function with IF function
Fig. 3 MEDIAN func­tion with IF function

Now, we’ve cal­cu­lat­ed the medi­an val­ue with a con­di­tion for each depart­ment. We can see that for HR it’s $4,000, for IT it’s $8,100 and for Mar­ket­ing it’s $5,900. Those are the mid­dle val­ues for each depart­ment (Fig. 4). 

Median values for each department
Fig. 4 Medi­an val­ues for each department

https://www.youtube.com/watch?v=DUYBBhR3wz4