ICAEW.com works better with JavaScript enabled.
Exclusive

Excel tips: the many uses of data analytics expressions

Author: Simon Hurst

Published: 31 Jul 2019

Exclusive content
Access to our exclusive resources is for specific groups of students, subscribers and members.
Simon Hurst breaks down how data analysis expressions work and what they can achieve.

As we have mentioned before, it’s probably no longer correct to think of Excel as a spreadsheet. It is now a spreadsheet/database hybrid with data manipulation and presentation features being the focus of the majority of recent enhancements and developments. One consequence of this is that the range of functions that were designed to work with cell-based content and calculation are no longer adequate to cope with the type of operations that the data analysis features require Excel to support.

Accordingly, Excel now includes two additional sets of calculation capabilities. Power Query/Get & Transform has its own ‘M’ language for working with data, including performing row-by-row calculations on tables. However, in this short series of articles, we are going to look at the other data-based calculation feature, Data Analysis Expressions (DAX).

DAX is used within the Power Pivot add-in and as part of the modelling section of Power BI. DAX can be used for row-by-row calculations but is perhaps most powerful when used to add Measures to the presentation and visualisation of data.

This first article seeks to explain how DAX works as the foundation for further exploration of what DAX can achieve in part two.

An Excel function by any other name?

There is some good news to start with: many DAX functions are the same as their Excel equivalents. For example, DAY(), MONTH() and YEAR() can all be used to extract part of a complete date using the same syntax as a cell-based Excel formula. Here we can see the use of the three functions entered as row formulae in the Power Pivot window (Figure 1).

Figure 1
Figure 1

Functions with added dimensions

While the three functions discussed above work like normal Excel functions and accept an argument that returns a single value, just like a reference to a single Excel cell, the real power of DAX comes from the ability of many DAX functions to encapsulate entire tables of data within the function.

In the following example, we are calculating the most recent orders that each of our salespeople is responsible for, using a row formula in the Employees table. To do this, we type a formula in the column adjacent to our existing columns to create a new, calculated column. We need to apply a ‘max’ calculation to a list of all the order dates in the Orders table for each employee. We do this by first creating a table of all the rows in the Orders table, where the Orders table EmployeeID matches the EmployeeID of the row in our Employees table. We then extract the OrderDates column from this table to create a list of all order dates for each employee. The max calculation then returns a single value from that list. The actual formula is:

=MAXX(RELATEDTABLE(Orders),Orders[OrderDate])

Unlike MAX() the MAXX() function allows us to use a table and an expression as the function arguments. We use the RELATEDTABLE() DAX function to return all the rows in the entire Orders table according to the database join on EmployeeID for each row of our Employees table. We then extract the single OrderDate column from this table for MAXX() to use to return the highest value (Figure 2).

Figure 2
Figure 2
We can use a PivotTable to demonstrate the way in which this DAX formula works in detail. If we create a PivotTable based on the Power Pivot data model and add Employee LastName as the row label and OrderDate as the Value, we can then set the Summarize Values By option to Max, to get the same results as our DAX formula, but displayed as a PivotTable. If we double-click on the Buchanan value for example, we can create a visualisation of the inner workings of our formula. We see the table that RELATEDTABLE() returns for the Buchanan row, the OrderDate column that is extracted by the second argument of MAXX() and, by sorting Newest to Oldest, confirm the most recent order date that MAXX() returns (Figure 3).
Figure 3
Figure 3

Within the DAX formula, this all goes on in the background, resulting in the return of the single value that we require.

In order to demonstrate the difference between normal Excel formulae and DAX, we created a row formula within a table in the Power Pivot window. The real power of DAX is probably not its use in this way, but rather the ability to create additional measures within PivotTables directly. In the next part of this series of articles we will look at some of the advantages of using measures and what they can add to the capabilities of PivotTables for presenting data.

Archive and Knowledge Base

This archive of Excel Community content from the ION platform will allow you to read the content of the articles but the functionality on the pages is limited. The ION search box, tags and navigation buttons on the archived pages will not work. Pages will load more slowly than a live website. You may be able to follow links to other articles but if this does not work, please return to the archive search. You can also search our Knowledge Base for access to all articles, new and archived, organised by topic.

 About the author

Simon Hurst
Simon Hurst The Knowledge Base

I trained as an accountant and two years after qualifying went to work for a software company - Orchard Business Systems, creator of the internationally-renowned Finax package. Following the takeover of the company by Paxus and then Solution 6 I left with two other former Orchard directors to set up The Knowledge Base. Over the years the other two have moved on to new and exciting ventures, leaving TKB to provide IT training, consultancy and strategic advice to mainly small and medium sized businesses. Most of my clients are firms of accountants or other professionals, but with a few others that came via recommendations from my practice clients. I spent 3 years as chairman of the ICAEW’s IT Faculty and I am still a committee member. I produce a newsletter aimed at accountants with an interest in IT and also write for the IT Faculty newsletter and AccountingWeb.

Open AddCPD icon