Sparklines Chart in cell | Excel Tips 30

If we want to show our data trend, we can use line charts, how­ev­er they are usu­al­ly large. If we want some­thing sim­ple and small, like a chart in a cell, we can use Sparklines.

Sparklines Chart in cell

All we have to do is to select one emp­ty cell, then go to the Insert tab, then go to Sparklines and select the Line Sparkline option. What we will get is a Cre­ate Sparkline win­dow, where we have to select a a prop­er range and check if loca­tion is good.(Fig. 1). 

 Creating a sparkline
Fig. 1 Cre­at­ing a sparkline

After press­ing OK and drag­ging it down, we have trends for oth­er coun­tries (Fig. 2). 

Ready trends
Fig. 2 Ready trends

If we want to add some mark­ers, we have to open the Mark­er Col­or bar and choose prop­er options (Fig. 3). 

Adding markers
Fig. 3 Adding markers

After adding mark­ers, spar­lines look as fol­lows. If we want to make them big­ger, we have two options. We can sim­ply enlarge the cells or we can merge a few cells using the Merge & Cen­ter option from the Insert tab (Fig. 4).

Cell merging
Fig. 4 Cell merging

Let’s insert a col­umn sparkline there (Fig. 5). 

Inserting a column sparkline
Fig. 5 Insert­ing a col­umn sparkline

I per­son­al­ly don’t like it too much (Fig. 6). 

Columns
Fig. 6 Columns

Let’s change it to line chart again (Fig. 7). 

Lines
Fig. 7 Lines

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

Pie Chart and Percentage % Data Labels | Excel Tips 29

If you have a small dataset, a pie chart is one of the best ways to show it. How can we insert a pie chart?

Pie Chart and Per­cent­age % Data Labels | Excel Tips #29

Let’s start with a sin­gle cell, then go to the Insert tab, then 2D Pie com­mand. And there we have it (Fig. 1). 

A new pie chart
Fig. 1 A new pie chart

We have to remem­ber that a pie chart will include the whole text before num­bers, which, in our case are cities and coun­tries. (Fig. 2). 

Whole text before numbers
Fig. 2 Whole text before numbers

We don’t want to see coun­tries because there will be too many names. Let’s delete our chart and select prop­er ranges, i.e. the City and the Num­ber of res­i­dents columns. Then, select the Insert tab, and 2D Pie com­mand (Fig. 3). 

A pie chart based on two columns
Fig. 3 A pie chart based on two columns

The best part of pie charts are Data Labels. I per­son­al­ly like the Data Call­out option best. We have the cat­e­go­ry name and per­cent­age there (Fig. 4).

Data Callout  option
Fig. 4 Data Call­out option

If you have dif­fer­ent kind of data, you can change the con­tent of data labels. We just have to click once on the pie chart and press Ctrl + 1 key­board com­bi­na­tion. We will see a table called For­mat Data Labels on the right, where we can select and des­e­lect what we wan to see in the labels (Fig. 5). 

Format Data Labels
Fig. 5 For­mat Data Labels

Some­times, we have to sort our data from largest to small­est or from small­est to largest (Fig. 6).

Data sorting
Fig. 6 Data sorting

Remem­ber that a pie chart is rec­om­mend­ed when you don’t have much infor­ma­tion to show. An opti­mal num­ber is around five pieces of infor­ma­tion. In case you have more, a pie chart will be less readable. 

https://www.youtube.com/watch?v=DMFad6D-6SE

Working hours and wages. Night shifts | Excel Tips #28

When we want to count the num­ber of work­ing hours in Excel, we have z prob­lem with night shifts. Let’ start with a human approach and day shift. 

Work­ing hours and wages. Night shifts | Excel Tips #28

In a day shift, the end time is larg­er that the start time, so we can just sub­tract one num­ber from anoth­er (Fig. 1). 

=(B2-A2)

Subtracting one number from another
Fig. 1 Sub­tract­ing one num­ber from another

After enter­ing and copy­ing down, we can see we have prop­er results for day shifts. In night shifts, when the end time is small­er that the start time, it does’t show us any time, only hash­tags. It hap­pened so because Excel refused to show any neg­a­tive dates or time. Even if Excel showed us neg­a­tive results, they would be wrong (Fig. 2). 

No negative time
Fig. 2 No neg­a­tive time

First, we have to remem­ber that Excel stores time as num­bers, i.e. the part of the day that has passed. When we look at the first hour, which is 8 am, it means that one-third of the day has passed. When we go to the Time bar, and press Gen­er­al, we can see that the time will be giv­en in dec­i­mal num­bers (Fig. 3), (Fig. 4). 

 General Time
Fig. 3 Gen­er­al Time 
Time in decimal numbers
Fig. 4 Time in dec­i­mal numbers

When we want to con­vert Excel time into human time, we have to mul­ti­ply it by 24 (Fig. 5). 

=(B2-A2)*24

Excel time into human time
Fig. 5 Excel time into human time

Now, we can see that the we can eas­i­ly read the val­ues. Remem­ber to have the Gen­er­al option select­ed. There are neg­a­tive val­ues for the night shift. What’s more, they are wrong, as there are only 8 hours from 8 pm to 4 am in row num­ber 3, not 16. 

Negative and wrong results
Fig. 6 Neg­a­tive and wrong results

It means that this human approach won’t work in Excel, so let’ delete the results. What can work here is a func­tion called MOD, which is also quite short. In the MOD func­tion, we also use the human approach, which means that from the end time we sub­tract the start time. How­ev­er, the MOD func­tion needs a divi­sor, i.e. 1, which means that it is one whole day (Fig. 7)

=MOD(B2-A2,1)

Divisor
Fig. 7 Divisor

Now, we can see that our results in day and night shifts are cor­rect. We can final­ly cal­cu­late the wages by mul­ti­ply­ing the num­ber of work­ing hours by the hourly wage (Fig. 8). 

=C2*$F$2

Calculating wages
Fig. 8 Cal­cu­lat­ing wages

As we can see the results are wrong again. Let’s have a look at row num­ber two. There are 8 hours, but Excel does­n’t mul­ti­ply 8 hours times 40$, but one third of a day times 40$, which gives us around $13 (Fig. 9).

Wrong results
Fig. 9 Wrong results

We want to have prop­er wages, so we need to mul­ti­ply it by 24 hours (Fig. 10).

=C2*$F$2*24

Multiplying by 24
Fig. 10 Mul­ti­ply­ing by 24

Now, we have prop­er wages (Fig. 11). 

Proper wages
Fig. 11 Prop­er wages

If you don’t need pre­ci­sion big­ger than 15 min­utes, just use num­bers instead of Excel time. I’m advis­ing it to you from my own experience. 

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

VLOOKUP all matches and combine them

Some­times, we want to find all the matched val­ues and com­bine them into one text string, i.e., we want o VLOOKUP all matched val­ues and then com­bine them.

VLOOKUP all match­es and com­bine them

I will give you two solu­tions. The first solu­tion will work from Excel 2019, and the sec­ond one will work in Dynam­ic Array Excel. First of all, we have to check if our rep­re­sen­ta­tive comes from the coun­try we are look­ing at. Let’s take a rep­re­sen­ta­tive from Spain. There is only one rep­re­sen­ta­tive of Spain in our exam­ple. We can check it using the IF func­tion, where we have to cre­ate a prop­er log­i­cal test. We have to take into con­sid­er­a­tion the Coun­try col­umn, so let’s write it by select­ing the col­umn and click­ing the F4 key to lock it. Then, we have to check if the val­ues from the col­umn are equal to just one coun­try (Spain) by click­ing the cell with the name of Spain (D4). It means that cell D4 will be com­pared to each cell from the Coun­try col­umn indi­vid­u­al­ly (Fig. 1)

Comparison to each cell
Fig. 1 Com­par­i­son to each cell

The log­i­cal test will return TRUE only in the case of Spain. In the case of oth­er coun­tries, it will return FALSE. If the log­i­cal test is in an array, we can choose prop­er, cor­re­spond­ing result as a return val­ue. We just need to select an array of the same size, which, in our case, is the Rep­re­sen­ta­tive col­umn. Then, we click the F4 key to lock it. When the log­i­cal test returns FALSE, we want to see an emp­ty text string, so we have to write a space in dou­ble quotes. Let’s close the func­tion with a paren­the­sis (Fig. 2)

=IF($A$2:$A$14=D2,$B$2:$B$14,” ”)

IF function
Fig. 2 IF function

Since I’m work­ing in Dynam­ic Array Excel, Excel spills the results to the whole col­umn (Fig. 3).

IF function results
Fig. 3 IF func­tion results

We can see that we have only one rep­re­sen­ta­tive of Spain, and many emp­ty cells. If we want to find the remain­ing rep­re­sen­ta­tives, we have to join the infor­ma­tion we have. To do that, we can use the TEXTJOIN func­tion, which is avail­able from Excel 2019. We have to give the func­tion a delim­iter. Let’s write a com­ma and a space in dou­ble quotes. Then, we have to decide whether we want to ignore emp­ty cells. We def­i­nite­ly do, so let’s write TRUE, or its short­er ver­sion, which is 1. Then, we just have to close the whole for­mu­la once again (Fig. 4).

=TEXTJOIN(“, “,1,IF($A$2:$A$14=D2,$B$2:$B$14,” ”))

TEXTJOIN function
Fig. 4 TEXTJOIN function

After enter­ing the for­mu­la and copy­ing it down, we have our results (Fig. 5). 

TEXTJOIN function results
Fig. 5 TEXTJOIN func­tion results

When we are in Dynam­ic Array Excel, we can use the FILTER func­tion instead of the IF func­tion. This func­tion just fil­ters our data. Let’s write FILTER func­tion. Our data is locat­ed only in one col­umn, which is the Rep­re­sen­ta­tive col­umn, so we have write the range and lock it with the F4 key. Then, we have to cre­ate an array of the same size with log­i­cal val­ues of TRUE or FALSE. It means that we have to cre­ate the same log­i­cal test as we did with the IF func­tion. Let’s add the Coun­try col­umn (A2:A14), F4 key to lock it, then an equal sign to check whether any of the val­ue from the Coun­try col­umn is equal to Spain (D2). After clos­ing it, we have a ready for­mu­la (Fig. 6).

=FILTER($B$2:$B$14,A$2:$A$14,=D2)

FILTER function
Fig. 6 FILTER function

We can see that Spain has only one rep­re­sen­ta­tive, but Poland has got three (Fig. 7). 

FILTER function results
Fig. 7 FILTER func­tion results

That’s why we have to put our FILTER func­tion results into the TEXTJOIN func­tion. And, once again, we have to write a com­ma and a space in dou­ble quotes. Then, we have to decide that we want to ignore emp­ty cells and close the whole for­mu­la (Fig. 8)

=TEXTJOIN(“, “,1,FILTER($B$2:$B$14,A$2:$A$14=D2))

TEXTJOIN with FILTER function
Fig. 8 TEXTJOIN with FILTER function

We can see that the results in the first solu­tion and in the sec­ond solu­tion are the same (Fig. 9)

Results
Fig. 9 Results

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

Count all cells containing certain text | Excel Tips #27

Some­times, we need to count all cells con­tain­ing cer­tain text. In our exam­ple, it will be a prod­uct name. 

Count all cells con­tain­ing cer­tain text | Excel Tips #27

Let’s assume that we want to count all cells con­tain­ing the name of eggs. In the In the bas­ket col­umn, we have cells where the name of eggs appears at the begin­ning, in the mid­dle, or at the end of the text. Some­times, the cell con­tains only eggs (Fig. 1). 

Eggs in many locations
Fig. 1 Eggs in many locations

In Excel, it’s a sim­ple task because we have the COUNTIF func­tion, where we can use wild­cards. Let’s start writ­ing the func­tion. We have to select a range, which is the In the bas­ket col­umn, F4 to lock it, then let’s write cri­te­ria. If we want to count only cells that con­tain only the word eggs, we would write D2 in the cri­te­ria, how­ev­er, we want to count the cells which con­tain eggs and oth­er prod­ucts as well. That’s why we have to add a wild­card, i.e. an aster­isk (*) that replaces any num­ber of char­ac­ters, even an emp­ty text string. So, we’re putting the aster­isk in dou­ble quotes, then we’re writ­ing an amper­sand to com­bine it with eggs, then D2, where eggs are. As we can see, eggs can be placed also at the end, that’s why we have to com­bine it with anoth­er aster­isk in dou­ble quotes. Our cri­te­ria look as fol­lows (Fig. 2). 

=COUNTIF($B$2:$B$20,”*”&D2&”*”

Our criteria
Fig. 2 Our criteria

When we press the F9 key, we can see how our cri­te­ria real­ly look (Fig. 3). 

=COUNTIF($B$2:$B$20,”*Eggs*”

Our criteria after F9
Fig. 3 Our cri­te­ria after F9

By press­ing Ctrl + Z, let’s return to the pre­vi­ous ver­sion, and close our for­mu­la (Fig. 4). 

=COUNTIF($B$2:$B$20,”*”&D2&”*”)

Our whole formula
Fig. 4 Our whole formula

After enter­ing and copy­ing the for­mu­la down, we can see how many cells con­tain cer­tain prod­uct (Fig. 5). 

Results
Fig. 5 Results

https://www.youtube.com/watch?v=Yv7Uiat–cs