How to group columns and rows

Today, we are going to learn how to group columns and rows. In our exam­ple, we have month by month sales, and their sum­maries by the first quar­ter, the sec­ond quar­ter and half a year with the use of the SUBTOTAL func­tion.

How to group columns and rows
Columns
Fig. 1 Columns

Some­times, we don’t want to show low­er val­ues, i.e. val­ues from indi­vid­ual months. We can do it by hid­ing those columns (Fig. 2).

Hide option
Fig. 2 Hide option

And some­times, we want to show those val­ues (Fig. 3). 

Unhide option
Fig. 3 Unhide option

Those tasks, how­ev­er, can some­times be a bit tedious. That’s why we are going learn how to group those columns to make it sim­pler. First, you have to select the columns you want, then go to the Data tab and click on the Group com­mand. Now, we can see a line above col­umn names, which allows us to hide the columns just by click­ing on the minus sign (Fig. 4). 

Grouped columns
Fig. 4 Grouped columns

We can also unhide them by click­ing on the plus sign (Fig. 5).

Unhiding the grouped columns
Fig. 5 Unhid­ing the grouped columns

Now, the task is quite sim­ple. You can hide or unhide many columns at once. We can group even more columns this way, how­ev­er, it’s impor­tant to have a space of at least one col­umn between those groups so that Excel does­n’t com­bine those groups in one (Fig. 6). 

Groups separated by one column
Fig. 6 Groups sep­a­rat­ed by one column

When we want to ungroup our data, there is a sim­ple solu­tion. You have to go to the Data tab, expand the Ungroup com­mand, and choose the Clear Out­line option (Fig. 7). This way, Excel will clear all groups in the sheet. Usu­al­ly, it’s eas­i­er to clear all groups and start cre­at­ing new groups from the begin­ning than try­ing to fix it. 

Ungrouping data
Fig. 7 Ungroup­ing data

Due to the fact that our val­ues are com­bined from dif­fer­ent columns, we can make Excel group the val­ues for us. You just select any cell, go to the Data tab, expand the Group com­mand and choose the Auto Out­line option (Fig. 8). 

Auto Outline option
Fig. 8 Auto Out­line option

This way, Excel has cre­at­ed three groups for us. Those groups aren’t on the same lev­el because each low­er lev­el group com­bines three columns, and the upper lev­el group com­bines all the columns from the low­er groups and a few more (Fig. 9). 

Groups on different levels
Fig. 9 Groups on dif­fer­ent levels

When we click on the group lev­el num­ber, Excel will expand or col­lapse all groups in this lev­el (Fig. 10). 

Group level numbers
Fig. 10 Group lev­el numbers

Now, let’s group some rows. We don’t have any func­tion that sums up or com­bines rows, so we have to do it man­u­al­ly. We have to select the rows we want, then go to the Data tab, then the Group option (Fig. 11). 

 Row grouping
Fig. 11 Row grouping

If we select a range, not whole columns or rows and press the Group com­mand, Excel does­n’t know which ones we want to group. Then we have to select the prop­er radio but­ton (Fig. 12). 

Selecting the proper option
Fig. 12 Select­ing the prop­er option

We can also select more rows and group them by press­ing the Group option to cre­ate a group on a high­er lev­el. This group will con­sist of groups from a low­er lev­el. We can expand and col­lapse them the using also lev­el num­ber but­tons (Fig. 13). 

Row group levels
Fig. 13 Row group levels

Dynamic chart title, link chart title with a value from the cell

Today, we are going to make a sim­ple trick, i.e. link­ing the Chart Title with a val­ue from a cell. It will make the Chart Title a bit more dynam­ic. The task is sim­ple. We have to select the chart, so that it has sol­id bor­ders. We go to the Chart Title edit mode. As we can see, the Chart Title bor­ders change into a dot­ted line, which we don’t want. We have to click some­thing else on the chart, then click again on the chart title one time, so that the bor­ders stay sol­id (Fig. 1).

Dynam­ic chart title, link chart title with a val­ue from the cell
Solid borders
Fig. 1 Sol­id borders

Now, we have to click the equal sign, which will appear in the for­mu­la bar (Fig. 2).

Equal sign
Fig. 2 Equal sign

We are start­ing to write a for­mu­la for the Chart Title. We are click­ing cell A1 because we want to have ref­er­ence to this cell. Then, we are press­ing Enter to link the Chart Title to this cell (Fig. 3). 

Chart Title linked to a cell
Fig. 3 Chart Title linked to cell A1

When we change a val­ue in the cell, the Chart Title also changes (Fig. 4).

Chart Title changes
Fig. 4 Chart Title changes

This sim­ple trick works also with Axis title. We have to select the Axis title (Fig. 5). 

Selected Axis title
Fig. 5 Select­ed Axis title 

Then, write the equal sign and select a prop­er cell. In our case it’s A10. After enter­ing it, the Axis title changes (Fig. 6). 

Axis title changed
Fig. 6 Axis title changed

We can do the same with the bot­tom Axis title (Fig. 7). 

Bottom Axis title changed
Fig. 7 Bot­tom Axis title changed

That’s how you con­nect the Chart title and Axis titles to val­ues from cells. 

How to extract last row

Today, we want to extract the last row with giv­en cur­ren­cies. Our data is sort­ed ran­dom­ly. If we want to con­sid­er the date col­umn, we will have to sort it first. We can do it man­u­al­ly, by going to the end of date and find the last row. How­ev­er, we want to sort it in Pow­er Query, which is more auto­mat­ic. We just have to select one cell from our table, go to Data tab, and click on the From Table/Range com­mand (Fig. 1). 

How to extract last row
 From Table/Range command
Fig. 1 From Table/Range command

This com­mand exports our data to Pow­er Query. We can see, that Pow­er Query con­sid­ers our data as a date and time. In our exam­ple, it isn’t impor­tant so let’s leave it like that. If we want to sort our dates, we just click on the A to Z sort­ing com­mand on the Home tab (Fig. 2). 

A to Z sorting command
Fig. 2 A to Z sort­ing command

Now, the last row is the newest date (Fig. 3). 

The newest date in the last row
Fig. 3 The newest date in the last row

Since we are inter­est­ed in cur­ren­cies, we want to group our data by the Cur­ren­cy col­umn. We have to click one cell from the Cur­ren­cy columns and go to the Group By com­mand in the Home tab. In the Group By win­dow that has appeared, we can see that the Cur­ren­cy bar is select­ed. In the Oper­a­tion bar, we need to select All Rows and, in the New col­umn name, let’s write tem­po­rary. Then we are press­ing the OK but­ton (Fig. 4).

Group By window
Fig. 4 Group By window

And we have our data grouped by cur­ren­cies (Fig. 5). 

Data grouped by currencies
Fig. 5 Data grouped by currencies

There is a table for each cur­ren­cy that con­tains all rows with a giv­en cur­ren­cy. We have sort­ed the dates ear­li­er, so in the tables, the last date is also the newest exchange rate. And the newest exchange rate is what we want (Fig. 6). 

The newest exchange rate
Fig. 6 The newest exchange rate

Let’s go to the Add Col­umn tab, then to the Cus­tom Col­umn com­mand. A win­dow will appear, where we write the name. Let’s call it Last. Then, we need to write a for­mu­la in the Cus­tom col­umn for­mu­la box. We are writ­ing Table.LastN com­mand to attract the last row of the table. The func­tion we are writ­ing needs a table, so we are choos­ing our table called tem­po­rary, then we need to write the num­ber of rows from the end. We want just one row, so let’s write it, then close the for­mu­la. This is the whole for­mu­la we need, so let’s press the OK but­ton (Fig. 7). 

=Table.LastN(temporary),1)

The formula
Fig. 7 The formula

We can see that we have the Last col­umn. In the col­umn, there are tables, but each table con­tains only one row for each cur­ren­cy (Fig. 8). 

The Last column
Fig. 8 The Last column

We don’t need the tem­po­rary col­umn, so let’s delete it (Fig. 9).

Deleting the temporary column
Fig. 9 Delet­ing the tem­po­rary column

Now, we can expand the Last col­umn by press­ing the icon shown in Fig. 10. In the win­dow that has appeared, we des­e­lect the Cur­ren­cy and the Use orig­i­nal col­umn name as pre­fix check­box­es. Then, we press the OK but­ton (Fig. 10). 

Expanding the Last column
Fig. 10 Expand­ing the Last column

Now, we can see a prop­er table with cur­ren­cy, and the newest date with the exchange rate. Let’s go to the Home tab, and Close&Load to com­mand (Fig. 11). 

Close&Load to command
Fig. 11 Close&Load to command

We moved back to Excel, where we have to select the Exist­ing work­sheet radio but­ton, then click on cell F1 and des­e­lect the Add this data to the Data Mod­el check­box, and press the OK but­ton (Fig. 12). 

Import Data
Fig. 12 Import Data

And we have our results. How­ev­er, we have to remem­ber that Pow­er Query not always extracts prop­er data for­mat­ting. That’s why we have to go to the Home tab and select prop­er data for­mat­ting (Fig. 13). 

Results with proper dates
Fig. 13 Results with prop­er dates

Let’s make a test and change some some dates in dif­fer­ent cur­ren­cies, then refresh our table (Fig. 14). 

Refreshing the table
Fig. 14 Refresh­ing the table

We can see that the Query is auto­mat­ic when we refresh it (Fig. 15). 

Automatic refreshing in Query
Fig. 15 Auto­mat­ic refresh­ing in Query

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

First day of the next month

Some­times, we want to get the first day of the next month. I will show you two solu­tions how to cal­cu­late this date in Excel. The first solu­tion uses the DATE func­tion. It needs the num­ber of days, months and years. First, we will write the num­ber of years, which we can extract­ed from the cur­rent date using the YEAR func­tion (Fig. 1).

First day of the next month

=DATE(YEAR(A2

DATE function
Fig. 1 DATE function

The same case is with the month num­ber. We are using the MONTH func­tion and extract­ing the num­ber from the date. How­ev­er, we have to remem­ber that we want to have the next month. That’s why we are adding +1. It’s impor­tant that the DATE func­tion will work with num­bers larg­er than 12. It will just go to the next year, or the pre­vi­ous one if the num­ber is low­er than zero. Then, we are putting 1 because we want the first day of the month. And just like that, we have the whole for­mu­la (Fig. 2).

=DATE(YEAR(A2),MONTH(A2)+1,1)

The whole DATE formula
Fig. 2 The whole DATE formula

After enter­ing and copy­ing it down, we have the results (Fig. 3).

DATE formula results
Fig. 3 DATE for­mu­la results

If we want to go fur­ther into the future, we just have to add more months, let’s say 3 (Fig. 4). 

=DATE(YEAR(A2),MONTH(A2)+3,1)

More into the future
Fig. 4 More into the future

We can see that the func­tion goes to next years in cer­tain dates (Fig. 5).

Next years in some dates
Fig. 5 Next years in some dates

If we want to go back in time, we have to sub­tract a num­ber, let’s write ‑3 (Fig. 6). 

=DATE(YEAR(A2),MONTH(A2)-3,1)

Going back in time
Fig. 6 Going back in time

And we are in the past. As we can see, the num­ber of years is also cal­cu­lat­ed ana­log­i­cal­ly (Fig. 7). 

In the past
Fig. 7 In the past

The sec­ond solu­tion uses the EOMONTH func­tion. We have our start­ing day and the num­ber of months we are mov­ing. Since we want to have the fist day of the next month, first, we need to go to the last day of the cur­rent month (Fig. 8). 

=EOMONTH(A2,0)

EOMONTH function
Fig. 8 EOMONTH function

And we have the last day (Fig. 9).

The last day
Fig. 9 The last day

How­ev­er, we want the day after, so we have to add 1 (Fig. 10). 

=EOMONTH(A2,0)+1

 Adding 1
Fig. 10 Adding 1

Now, we have the first days of the next months (Fig. 11). 

The first day of the next months
Fig. 11 The first day of the next months

When we want to have the first day of the month that is three months into the future, we just have to add 2 months in the sec­ond argu­ment of the EOMONTH func­tion. It’s because we will go 2 months into the future, and then we have +1 at the end, so it sums up to 3 months (Fig. 12).

=EOMONTH(A2,2)+1

3 months into the future
Fig. 12 3 months into the future

And we have prop­er dates (Fig. 13).

Proper dates
Fig. 13 Prop­er dates

Ana­log­i­cal­ly, when we want to go back in time, we need to write one month more than we real­ly want as a neg­a­tive num­ber because we are going to the last day of the month and then we are adding 1, so in total we are going back 3 months (Fig. 14). 

=EOMONTH(A2,-4)+1

3 months into the past
Fig. 14 3 months into the past

And we have the solu­tion (Fig. 15). 

Solution
Fig. 15 Solution

The results are the same, so it’s up to you which solu­tion you will choose. 

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

Last day of a month, EOMONTH function

Some­times, we need to know what the last day of the moth is. In fact, it’s real­ly sim­ple to find it out because we have the end of month func­tion — EOMONTH. This func­tion needs a start­ing day and the num­ber of moths we are mov­ing. When we want the end of the cur­rent month, we just put 0 in the sec­ond argu­ment of the func­tion. Then, we must close the for­mu­la and that’s it (Fig. 1).

Last day of a month, EOMONTH function

=EOMONTH(A2,0)

OEMONTH function with 1
Fig. 1 OEMONTH func­tion with 0

We have the last days of cur­rent months. The EOMONTH func­tion shows the last day even if the start­ing day is the last day of the month (Fig. 2).

EOMONTH with current months
Fig. 2 EOMONTH with cur­rent months

The EOMONTH func­tion can move to the future. When we want to go one month into the future, we just put pos­i­tive num­ber (for exam­ple 1) instead of 0 (Fig.3).

=OEMONTH(A2,1)

OEMONTH with 1
Fig. 3 OEMONTH with 1

And we have the last days of the next month (Fig. 4).

Last days of next months
Fig. 4 Last days of next months

If we put a big­ger num­ber (Fig.5),

=EOMONTH(A2,3)

EOMONTH with a bigger number
Fig. 5 EOMONTH with a big­ger number

we will move more into the future (Fig. 6). 

More distant months
Fig. 6 More dis­tant months

Ana­log­i­cal­ly, if we want to move back in time, we just write a neg­a­tive num­ber. Let’s write ‑1 (Fig. 7). 

=EOMONTH(A2, ‑1)

EOMONTH with a negative number
Fig. 7 EOMONTH with a neg­a­tive number

And we are in the pre­vi­ous month (Fig. 8).

Previous months
Fig. 8 Pre­vi­ous months

If we want to move even more into the past, we just write big­ger neg­a­tive num­bers (Fig. 9).

=EOMONTH(A2,-3)

EOMONTH with a bigger negative number
Fig. 9 EOMONTH with a big­ger neg­a­tive number

As a result, the EOMONTH func­tion can move us even to pre­vi­ous or next years (Fig. 11). 

Previous or next years
Fig. 11 Pre­vi­ous or next years