Adding Business Logic with DAX
Adding Meaning to a Data Model
There are two different ways of adding meaning to your data model.
Calculated Columns
A way to add columns to your tables based on a formula or expression.Measures
A way of creating your own aggregations of the data.
Having data does not automatically translate into business value. Let's say that I have order years as a filed on my sales table. What if I were to take the sum of order year? What would that mean? Absolutely nothing, it would be gibberish. Now, that may seem like a silly example, but it does help prove a point. Data by itself is meaningless. It requires an appropriate context and understanding. To add value, you have to understand the business domain, and find ways to enrich the data with that context and meaning.
DAX is what allows us to add a layer of meaning to the data, to encapsulate complexity so it's accessible to end-users. Your job is to add meaning.
How Do You Add Meaning?
We mentioned in DAX, there are two ways you can do that. The problem is, it can be very confusing at times. This is because it can be hard to tell which way makes the most sense for a given problem. And, it can look a bit redundant, but in fact, these two ways serve two distinctly useful purposes.
The first method is Calculated Columns
Expands a table by adding columns defined by an expression.
This essentially expands your data horizontally by a dding a new column. That column is treated the same as all the other columns in your table. This method is intuitive, and easy to get a handle on.
The other method is Measures
Summarize all of the data into a single value.
Measures summarize your data vertically, condensing columns into singular values. Measures are best thought as a way of describing key performance metrics. While Calculated Column allows you to combine a price and quantity to get extended price, Measure allows you to summarize and to get, say, average sales, or year-over-year growth for sales, for example.
Deciding Which to Use
So, when do we use each of these different methods?
Calculated Columns
Ideal for operational, detailed information.
Calculated Columns are, by nature, much more operational. So, they are much more like a Swiss Army Knife, where you are just trying to set something done. By default, they can only look within the row they're evaluating. SO, their scope is often very small. It's difficult to tell someone much about the entire enterprise based on a single sales entry. That's like taking a random entry in the phone book, and try to extrapolate information about the entire county.
Measures
Ideal for analytical, summary information.
Measures, in contrast, are often very analytical by nature. They're taking whole columns of data and condensing them into a single value. That value usually has some sort of implied meaning. Think about the metric of year-over-year growth, for example. How much revenue fif we make compared to last year?
Well, if I were to show a company grew 10% over last year, that would involve looking at two entire years of revenue. It would also have an implied meaning along with it, because for a stable company, 10% annual growth is pretty good. But for a startup, 10% growth could be a death knell.