|

Excel: Reporting Text in a Pivot Table

By Bill Jelen
July 1, 2018
8 comments

Pivot tables are excellent for summarizing numbers. At one of my Power Excel seminars recently, someone wanted to show a text field in the Values area of a pivot table. Thanks to the Data Model and the new DAX function CONCATENATEX introduced in 2017, you can build such a pivot table.

 

 

The attendee said, “I have a data set showing the prior and current status for support tickets. I want to report the text from the Status field in the Values area of a pivot table.” While the Data Model, introduced in Excel 2013, and CONCATENATEX provide a solution, these calculations are only available in Windows versions of Excel. They won’t work in Excel for Android, Excel for iOS, or Excel for Mac.

 

DAX stands for Data Analysis eXpressions. The DAX formula language is a new set of functions for creating calculated fields in a pivot table. While many of the functions are similar to the functions in regular Excel, there are several powerful additions that allow calculations previously impossible in a pivot table.

 

In order to use DAX in a pivot table, follow these steps:

 

1. Select one cell in your data set and press Ctrl+T (or go to Home, Format as Table).

2. By default, the new table will be called Table1. Click on the Table Tools Design tab in the Ribbon and assign the table a name. The table name can’t have spaces. A name such as “TicketData” would work.

3. Select one cell in the table. From the Insert Tab, choose Pivot Table.

4. In the Create Pivot Table dialog, choose the box for “Add this data to the Data Model.”

 

 

5. A new worksheet will appear with the Pivot Table Fields list. Start to build your pivot table by dragging fields to the Rows and Columns area. When your pivot table is based on the Data Model, there will be a few subtle differences in the Pivot Table Fields list. First, the words “Active and All” allow you to add more data sets to the pivot table. Second, the name of the table appears at the top of the fields from that table.

 

6. Right-click the name of the table and choose Add Measure.

 

 

Note: The word “Measure” is a database professional’s word for Calculated Field. When the Power Pivot add-in debuted in Excel 2010, the calculated fields were called Measures. Microsoft tried to soften the word in Excel 2013, and the menu choice in Figure 1 appeared as Insert Calculated Field. This was designed to be more familiar for people using Excel. But Excel pivot tables already offer a different feature called Calculated Fields. To avoid confusion, the term changed to “Measure” in Excel 2016. I would have preferred a completely new term, such as “Super Amazing Calculated Field.”

 

7. In the Measure dialog, type a measure name such as “StatusResults.”

8. Enter the formula =CONCATENATEX(TicketData,[Status],”, “).

9. Click the Check DAX Formula button to make sure the syntax is correct.

10. You can specify the number format for Measures, which I think is great. For a text result, however, the only valid choice is General, so leave the number format as General.

 

 

Note: The syntax for CONCATENATEX is (Table Name, Expression, Delimiter). In the formula in Step 8, TicketData corresponds to the name that you used in Step 2, and [Status] is the name of the field in the source data. To use the AutoComplete feature in the Create Measure dialog, type a left square bracket. The AutoComplete list will show a list of fields from your data set. Click on one name, and press Tab.

 

11. Click OK to create the new calculated field. The calculation won’t show up in the pivot table automatically. Instead, a new field will appear in the Pivot Table Fields list. Drag the new field to the Values area.

 

The Subtotal and Grand Total results for a text field might be unexpected. The Grand Total Column of Apple and Quince will be “Apple, Quince.” The Subtotal for the Central region will be “Orange, Apple, Apple, Vanilla, Elderberry, Mango, Watermelon.” As you can imagine, the bottom-right cell containing the grand total will contain one word for every row in the original data. These results cause the pivot table columns to be unreasonably wide.

 

 

In many cases, the pivot table will look better if you remove the grand totals and subtotals:

 

12. Select Design, Grand Totals, Off For Rows and Columns.

13. Right-click on the first Subtotal label in Column A and unselect Subtotal Region.

 

The result is a pivot table with text in the Values area.

 

 

Just like any other pivot table, you can rearrange the fields in the Rows and Columns area and the results will recalculate.

 

 

Download this month’s workbook to try it out for yourself: SF-2018-07-TextValues.

 

Update from Bill Jelen: After using this method for a few weeks, I and others noticed that in some data sets, the concatenated values would contain duplicates. You can remove the duplicates by changing =CONCATENATEX(TicketData,[Status],”, “) to =CONCATENATEX(Values(TicketData[Status]),TicketData[Status],”, “). (Thanks to Rob Collie at PowerPivotPro.com for suggesting the updated formula.)

The VALUES function returns a new table with the unique values found in a column.

 

SF SAYS

 

The DAX formula language offers many new calculations for your pivot tables.

 

Bill Jelen is the author of MrExcel XL: 40 Greatest Excel Tips. Send questions for future articles to IMA@MrExcel.com.
8 + Show Comments

8 comments
    Anna August 12, 2018 AT 3:16 pm

    Hello Bill, Thank you for the article. I need this function very much, However, I followed all the steps, but my pivot doesn’t give add measure field. What can be the problem? Thank you and have a great day. Anna

    Duncan Williamson August 17, 2018 AT 8:25 pm

    Isn’t this a top tip. On my system, it is usual for the ” character to paste badly when I go from a web page to Excel or from Word or PowerPoint to excel.

    What this means is that when I copied your first concatenatex() formula, it didn’t work. until if retype “, ” at the end of the formula then it works as normal

    cb September 11, 2018 AT 5:15 am

    This works flawless. Thank you, I have been looking for this for such a long time. Eventually. super thx

    harish ahuja September 29, 2018 AT 2:36 am

    thank you so much bill and special thanks to rob colliee
    who makes this pivot work.

    VB October 23, 2018 AT 10:46 am

    I am unable to add the new calculated field in the ‘Values’ field of my pivot table – any ideas what the issue might be?

    Aaron October 24, 2018 AT 11:46 am

    Thanks very much, this is fantastic. Exactly what I was looking for.

    Lindsey October 31, 2018 AT 10:08 am

    Is there a way to keep the values from all subtotaling without turning subtotals off completely since there is other numerical data in the rows to be summed up? I know of the conditional formatting way with custom number “;;;”, but I was hoping there was something I could apply directly to the logic instead.

    Alex November 14, 2018 AT 11:07 am

    I am running into the same issue as VB. I am unable to drag the new measure into the values box. There is no error, I just drag and drop, the cursor hourglass spins for a fraction of a second, then nothing happens.

You may also like