Combine all unique values within a group | Excel Power Query 04

Let’s assume that we are in the future and we sell space­ships. We want to find out what class of a space­ship each coun­try has bought bas­ing on our table of unique space­ship classes. 

Com­bine all unique val­ues with­in group | Excel Pow­er Query 04

With Pow­er Query, this task is very sim­ple. We have to select our main table, then go to the Data tab and choose the From Table/Range com­mand in order to export our data from Excel to Pow­er Query (Fig. 1).


Fig. 1 Exporting data to Power Query
Fig. 1 Export­ing data to Pow­er Query

Since we are inter­est­ed which coun­try has bought which space­ship, we want to group our data by the coun­try. We have to select the Coun­try col­umn and go to the Home tab (1) and choose the Group By com­mand (2). In the win­dow, we need to choose the Advanced option (3) because we want to add more aggre­ga­tion. I want to count how many ships each coun­try has bought as well as know the space­ship class names. Since there isn’t any prop­er oper­a­tion, let’s choose the Sum option (4), which we will mod­i­fy lat­er in the code. In the col­umn bar, we’re choos­ing the Ship class (5). As a final step, let’s write a new name, which is going to be ‘Unique ship class­es’ (6) (Fig. 2)

Data grouping
Fig. 2 Data grouping 

In the new table, there are some errors in the last col­umn, because we want­ed to sum up text, which is impos­si­ble. It means that we need to mod­i­fy our code. We need to go to the View (1) tab and tick the For­mu­la bar check­box (2). We can see that the for­mu­la uses the List.Sum func­tion (3) (Fig. 3)

Formula bar
Fig. 3 For­mu­la bar

What we want to do is com­bine all val­ues, so let’s change the List.Sum into the Text.Combine func­tion (1). We also need to add a sep­a­ra­tor, which will be a com­ma and a space (2) (Fig. 4)

Code modification
Fig. 4 Code modification

Now, we can see that Pow­er Query has changed its cal­cu­la­tions. All ship class­es are com­bined. How­ev­er, as I said before, we need only unique val­ues with­out repeats. We just need to add one func­tion, which is the List.Distinct func­tion. (Fig. 5)

List.Distinct function
Fig. 5 List.Distinct function

Now, we can see there are no repeats. We can go to the Home tab (1) and to the Close & Load com­mand (2) and the Close & Load to option (3) (Fig. 6)

Going back to Excel
Fig. 6 Going back to Excel

In Excel, we have to remem­ber to select the Table (1) and Exist­ing work­sheet (2) radio but­tons. Then choose a tar­get cell (Fig. 7)

Data importing
Fig. 7 Data importing

As we can see, we have count­ed how many ships each coun­try has bought as well as the prod­uct class (Fig. 8)

 The final table
Fig. 8 The final table

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

Advanced Filters and between condition

Today, we want to learn how advanced fil­ters work in Excel, espe­cial­ly between conditions. 

Advanced Fil­ters and between condition

Let’s start. When we have our dataset, we write our advanced fil­ter con­di­tions in cells. We need to have a head­er and a con­di­tion for this head­er. If we write con­di­tions in one row, all of them are con­nect­ed with the final cri­te­ria. It means that each con­di­tion should be met in order to take out the whole row from our dataset (1). When we add con­di­tions to fur­ther rows, it meas that it’s an ‘or’ con­di­tion (2). In this case, we will look for straw­ber­ries or plums. If we want to cre­ate a between con­di­tion, we need to write the head­er two times (3) in order to cre­ate a com­mon part. In our case, we are look­ing for straw­ber­ries that are equal or greater than 500 and small­er or equal to 750, and in the case of plums we want the plums that are equal or greater than 300 and small­er or equal to 500. We have to remem­ber that those con­di­tions should make a com­mon part (Fig. 1)

Dataset with two headers
Fig. 1 Dataset with two headers

When we want to go to advanced fil­ters, we need to select one cell in our dataset (1), then go to the Data tab (2), then Advanced fil­ters (3). In the Advanced fil­ter win­dow press the Copy to anoth­er loca­tion radio but­ton (4), and select the cri­te­ria range (5). The last step is select­ing the tar­get cell, which will be cell E6 (6) (Fig. 2)

 Creating a table
Fig. 2 Cre­at­ing a table

Remem­ber that if con­di­tions are writ­ten in one row, they are com­bined as an ‘and’ con­di­tion, and when they are in sep­a­rate rows, they are com­bined as an ‘or’ con­di­tion. More­over, we can add an emp­ty con­di­tion for dif­fer­ent head­ers. But, since there isn’t any con­di­tion in the Date col­umn, we can select the range with­out it. In fig­ure 3, we can see the final table with sales of plums that are between 300 and 500 and sales of straw­ber­ries that are between 500 and 750, togeth­er with all pos­si­ble dates for those con­di­tions (Fig. 3)

 Final table
Fig. 3 Final table

https://www.youtube.com/watch?v=PihjS8Bq-vI&t

Advanced Filters and wildcards

Today, we want to learn how wild­cards work with advanced filters. 

Advanced Fil­ters and wildcards

First of all, we have to remem­ber that an aster­isk replaces any text string, even an emp­ty one. A ques­tion mark replaces any sin­gle char­ac­ter. A tilde dis­ables a wildcard. 

Let’s start with find­ing ‘Red’ in the Prod­uct col­umn. To do that, we have to select one cell in our data, then go to the Data tab (1) and click on the Advanced fil­ter com­mand (2). In the Advanced fil­ter win­dow, we have to select the Copy to anoth­er loca­tion radio but­ton (3), then write the Cri­te­ria range (4). In the Copy to bar, we select our tar­get cell (5).

Advanced filter window
Fig. 1 Advanced fil­ter window

After press­ing OK, we have our results. In advanced fil­ters, we don’t have a sim­ple con­di­tion with text. This con­di­tion is not an equal con­di­tion, but a ‘starts with’ con­di­tion. In our tar­get col­umn, we have the ‘red’ word, how­ev­er, advanced fil­ters chose whole cells that start with ‘red’. If we want only the exact word, we have to write it with a sin­gle quote, then equals, then our word. Let’s write it. We should make anoth­er advanced fil­ter, so let’s make the same steps as in the pre­vi­ous exam­ple, start­ing with the Data tab and chang­ing the Cri­te­ria range to anoth­er col­umn (1) (Fig. 2)

Advanced filters with an exact word
Fig. 2 Advanced fil­ters with an exact word

In the tar­get cell, we can see only one cell with Drag­on­Fly, even though there are three cells with Drag­on­Fly in our data. 

Now, let’s try the aster­isk option. We write an aster­isk before ‘bee­tle’, but we have to remem­ber that it is always con­nect­ed with the ‘starts with’ option. We are work­ing with wild­cards as well as with the ‘starts with’ cri­te­ria. It works as if an aster­isk was also at the end of ‘bee­tle’. Let’s make a prop­er advanced fil­ter for this case star­ing with the Data tab and chang­ing the Cri­te­ria range into anoth­er col­umn (1) (Fig. 3)

 Advanced filters with an asterisk
Fig. 3 Advanced fil­ters with an asterisk

As we can see, ‘bee­tle’ can be at the end, at the begin­ning or even in the mid­dle of our cell.

Now, let’s work with ques­tion marks. We need to remem­ber that one ques­tion mark rep­re­sents only one sign. It can be a dig­it, a let­ter or any oth­er sign. For exam­ple ‘Ant ? — ? mm’ can­not rep­re­sent ‘Ant 6 — 10 mm’, because there are too many signs in 10. Let’s make an advanced fil­ter for that. We start with the Data tab, and we change the Cri­te­ria range (1) and the tar­get cell (2) (Fig. 4)

Advanced filters with an asterisk
Fig. 4 Advanced fil­ters with an asterisk

We can see that we found two cells where a ques­tion mark rep­re­sent­ed only one sign. 

Now, let’s move on to a tilde. We want to find the exact phrase of ‘*Ant’. That’s why we put a tilde at the begin­ning. If we put only an aster­isk and an Ant, like this ‘*Ant’, Excel would find any Ant, regard­less of its posi­tion. The tilde makes the aster­isk stop being a wild­card. We do the same as in pre­vi­ous cas­es, chang­ing only the Cri­te­ria range and the tar­get cell (Fig. 5)

 Advanced filters with a tilde
Fig. 5 Advanced fil­ters with a tilde

We can see that Excel found only one Ant with an aster­isk at the begin­ning. It’s because we turned off wildcards. 

https://www.youtube.com/watch?v=oRH3-S9v-8Q

How to Create A Pareto Chart 

Do you want to put a Pare­to chart in Excel? I will show you how.

How to Cre­ate A Pare­to Chart 

If you want to put a chart on which you have columns that rep­re­sent income and a line that rep­re­sents the cumu­la­tive per­cent income, fol­low me. 

From Excel 2016, you can sim­ply go to the Insert tab and choose the Pare­to chart from the His­togram com­mand (Fig. 1)

Inserting a Pareto chart
Fig. 1 Insert­ing a Pare­to chart

And you have the Pare­to chart ready. How­ev­er, the charts from Excel 2016 have some draw­backs. The line isn’t an actu­al series of the chart. It means that we can­not add data labels there. That’s why I don’t pre­fer using this type of chart. What I pre­fer is the ear­li­er ver­sion that gives me more free­dom con­cern­ing val­ue chang­ing, although it requires more cal­cu­la­tions. We have to cal­cu­late the cumu­la­tive per­cent income on our own (Fig. 2)

=SUM(B$2:$B2)/SUM($B$2:$B$9)

Cumulative percent calculations
Fig. 2 Cumu­la­tive per­cent calculations

Now, we can insert a sim­ple col­umn chart. Since the income is enor­mous­ly big­ger that the per­cent­age, we aren’t able to see the income columns at all, but we want to select them (Fig. 3). How can we do it?

No % Income columns
Fig. 3 No % Income columns

We can select our chart and go to the For­mat tab. On the left we can see all ele­ments of the chart. We are inter­est­ed in the Series “% Income” option (Fig. 4)

Series "% Income"
Fig. 4 Series “% Income”

We can see now that the series is select­ed on the chart. Let’s press Ctrl + 1 and go to For­mat Data Series, Series Options, Plot Series On, and select the Sec­ondary Axis option. Now we have % income on a dif­fer­ent axis (Fig. 5)

Secondary Axis options
Fig. 5 Sec­ondary Axis options

Now, we can change the chart type into a chart that will rep­re­sent income bet­ter. We have to click on the chart ele­ment once, then go to the Insert tab and the Line chart with Mark­ers option (Fig. 6)

Line Chart with Markers
Fig. 6 Line Chart with Markers

Since we are cre­at­ing a Pare­to chart our­selves, the val­ues aren’t sort­ed and we have to do it man­u­al­ly. We just select one cell in our data, then go to the Data tab and choose the from Z to A option (Fig. 7)

 Data sorting
Fig. 7 Data sorting

Now the data on the chart is nice­ly sort­ed and it looks more like a Pare­to chart. We still have to add mod­i­fi­ca­tions to make it a real Pare­to chart. First of all, let’s select a col­umn and press Ctrl + 1. On the right, we have the Gap Width option. Let’s slide it to 0%. Now, let’s go to the sec­ondary axis. It goes up to 120%, how­ev­er our max­i­mum is 100% (Fig. 8)

Gap Width modification
Fig. 8 Gap Width modification

We have to select the axis, press Ctrl + 1, go to Axis Options and write 1 in the Max­i­mum bar, which equals 100%. We also change our Major Units to 0.2 which means that there will be less per­cent num­bers showed on the axis (Fig. 9)

Less percent numbers
Fig. 9 Less per­cent numbers 

We still don’t need the 0 after dot in our per­cent­ages, so let’s go to Num­bers and change the For­mat Code from 0.0% to 0% and click Add (Fig. 10)

Format Code change
Fig. 10 For­mat Code change

Now, let’s go to the Income For­mat Axis. Press the axis and Ctrl + 1. Let’s change the Major from 100000 to 200000. This way the chart will show less num­bers (Fig. 11)

Less numbers
Fig. 11 Less numbers

What I care about the most right now are data labels for the line. Let’s click once on the line, click on the plus sign and we have Data Labels option. Let’s place them above our line (Fig. 12)

Data Labels
Fig. 12 Data Labels

We still need to set a prop­er title. Let’s just write Pare­to. After imple­ment­ing the most impor­tant changes, the Pare­to chart looks like that (Fig. 13)

Finished Pareto chart
Fig. 13 Fin­ished Pare­to chart

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

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