A magical Excel trick for flattening data copied from a PivotTable report in tabular layout into usable format

Magical Trick for Data Flattening in Excel

Here is a scenario that I come across sometime ago when I received an Excel file with some apparently messy data for further processing to generate another report. The data in the file appear similar to below screenshot. This data is self-explanatory. It’s the sales in units and dollars of each product under each product category made by each sales person. If you observe the data, for all the sales made by each sales person, name of the sales person is listed only once. Same goes with product category appearing only once for each product.

Now the challenge is to flatten the data in a way that for each product row, respective product category and sales person name should get repeated. Only then, it becomes consumable in downstream process for further preparation of another report. By the way, this is just some fictitious small amount of data. The file I received has more than a few thousands of records, which means it’s not feasible to perform this task manually.

By the way, this kind of data mess happens when you copy the data from a PivotTable report in Tabular Layout, with Repeat All Item Labels option not selected under Layout group of Design tab, +/- toggle button disabled under Show group of Analyze tab of PivotTable Tools ribbon; and then paste the values of such copied data to different location for the further sharing, like it was shared with me.

ExcelDataFlatteningSource

Here is a magical trick to complete this task accurately in just a couple of steps:

Step.1. Apply filter to the header row. Click on Salesperson field filter drop down. Deselect all items and then select only blanks. Hit OK.

The data looks as below after this step.

image

Step:2. After applying the filters, observe that the cell address of the first blank cell in Salesperson column is A4 (boxed in red). This means that the cell above A4 (i.e., cell A3) is the first non-blank cell. This gives us a logic that the value in A4 should have been the same as the value in cell A3. So, just enter the formula =A3 in cell A4. The same logic applies for all the other blank cells too. So, copy the formula to the rest of the blank cells. After this, clear the applied filters from salesperson column header. That works the MAGIC..!! This completely fills up all the blank cells in the Salesperson column accurately as in the below screenshot:

image

Repeat these two steps for Category column as well. The magical trick works there too..!!

For more such tricks follow the blog. Hit the likes if you like the trick. Happy Learning..!!

Advertisements

Flash Fill Trick in Excel 2016

ExcelFlashFill

Here is a very common exercise that you might have or may come across – You have full names of employees in a column and you are expected to extract last names from these full names into a separate column. In versions prior to Excel 2013, you need to use formulas and functions to accomplish this task. Below screenshot shows an example of how this is achieved and the formula used. Cells A3 to A7 have full names (First name followed by last name), cells B3 to B7 have formulas to extract only last name from the full name.

Extracting Last Name from Full Name using Excel Formula

Starting from Excel 2013, you don’t have be an expert in formulas and function to achieve this task, instead you have magical built-in tool called Flash Fill at your rescue. In our example, in cell B3, instead of typing any formula, manually type the last name from the full name contained in cell A3. Since cell A3 has the text – “Balakrishna Sappa”, the last name from this full name is “Sappa”. Now in the next cell, i.e., cell B4, just type first letter of the last name from the corresponding full name. In this example, since cell A4 has the text – “John Short”, the first letter in the last name is “S”. Soon as you type “S” here, you will see Excel suggesting you rest of the letters to complete your work. In our example, Excel is suggesting the complete text as “Sappa”. i.e., Excel is looking at the values present in the cells immediately above the active cell and accordingly suggesting you. This feature in Excel is called “Auto Complete”.

ExcelAutoFill

But evidently, this doesn’t serve our purpose. So, in the above step, instead of accepting Excel’s suggestion, continue typing the second letter in the last name. i.e., you must type “Sh” in cell B4. Now, Excel rightly suggests the last names for all the rest of the full names including the one in the active cell. See the below screenshot. Just hit enter and you are done with the task. No knowledge of formulas and functions needed to complete the task. This feature of Excel is called Flash Fill.

FlashFill1

Note: An important point to remember to make use of Flash Fill is that you must enter the complete first value manually and at least first letter in the second row value. In our example, we have manually entered the complete last name value in cell B3 and first two letters in the last name of the second row. This is because, these are the steps that enable Excel’s Flash Fill to work its intelligence.

The above screenshots are from Excel 2016.

Hope that saved or will save you time by large when you are confronted with this or similar seemingly intimidating tasks..!!

Happy Learning..!! Do leave your comments and hit the likes if you find this useful.

New function in Excel 2016 to display in a cell, the formula contained in another cell

New function in Excel 2016 to display in a cell, the formula contained in another cell

You must have come across a number of situations when you were trying to explain a formula that you have written in Excel and the result of the formula. This kind of situation basically demands both the formula expression and the formula result to be displayed simultaneously. For example, from the below screenshot, if you are trying to explain that the formula in cell G2 is =TODAY() and that this is a built-in function in Excel that returns today’s date, you might instruct to view the result in the cell (active cell in the below screenshot) and to view the formula contained in the active cell from the formula bar (highlighted in rounded box in below screenshot).

 

image

 

what if I you want to see both formula and the result of the formula side by side or one below the other and avoid viewing two extreme corners of the window? Excel offers a new function named FORMULATEXT to address this purpose. FORMULATEXT function takes only mandatory argument referring the address of the cell containing formula that you wish to view. It returns the formula contained in the cell whose address is passed as the only argument to it. In our example, if you enter the formula =FORMULATEXT(B2) in cell F2, it returns the value as =TODAY() as in the below screenshot. Now the formula used in cell G2 and the value returned by it are just side by side making it easier to understand the formula and explain it to others too.

 

image

 

A nifty handy formula for people like me Smile Happy Excel Learning..!!

Trick for Listing the names of all sheets in Excel workbook

List of Sheet Names output

Here is a 2 step technique to retrieve the names of all sheets in Excel workbook:

Step:1. First define a named range using the below formula:

Step: 1a. Click “Define Name” command in “Define Names” group under “Formulas” ribbon tab to invoke “New Name” dialogue

Step: 1b. Let the name of the range be “SheetNames”

Step: 1c. Let the name refer to the range defined by the formula: = Get.Workbook(1)

Step: 1d. Click OK

New Name Dialogue
New Name Dialogue

 

 

Step:2. Write  the below array formula simply referring to the range name defined in Step 1 to get the names of all the sheets in the current workbook listed:

– Since there are 3 sheets in the workbook in the screenshot, select any three consecutive cells in a row.

– Enter “=” to start writing the formula and then type the range name defined in Step.1 as in the below screenshot:

Array Formula referring the defined Name
Array Formula referring the defined Name

 

– Hit CTRL + SHIFT + ENTER , to enter the formula as array formula and the list of all sheet names are listed. See the below screenshot:

List of Sheet Names output
List of Sheet Names output

Note that the sheet names are listed along with the workbook name. You can write a formula using Excel’s built-in functions to extract only sheet name from these names that are qualified by the workbook name.

Happy learning..!! Do leave your comments.