Press "Enter" to skip to content

Category: DAX

Using VALUES in Iterators in DAX

Marco Russo and Alberto Ferrari answer a question:

In a previous article, Choosing between DISTINCT and VALUES in DAX, we explained how to choose the proper function to iterate the unique values visible in a column in the current filter context. We suggest reading that article before starting this one, because it describes the same underlying problem. Here, we discuss whether to use VALUES in an iterator. This choice depends on the answer to this question: Do you want to include or exclude the blank row generated by an invalid relationship when iterating over the rows of a table reference?

Read on to see how the answer affects your decision.

Leave a Comment

Sorting a Visual by a Field Not on the Visual

Nikola Ilic does a bit of sorting:

Recently, I was dealing with a Power BI report where the client had a very specific requirement – to sort the data in the visual based on a particular field from the semantic model. The only “issue” was that this particular field wasn’t part of the visual. So, while figuring out how this can be accomplished (because, yes, everything can be accomplished when the client needs it, hehe), I decided to write it down and share it with everyone who might find it useful.

Nikola successfully uses machine trickery to solve the problem.

Leave a Comment

Using the DAX FILTER Function

Ben Richardson digs into a function:

If you’ve ever tried to build a measure that needed more filtering power than a basic slicer, you’ve probably hit a wall.

That’s where DAX’s FILTER function comes in.

While visual filters and slicers work great for basic scenarios:

FILTER gives you row-level control to create sophisticated calculations that respond dynamically to your business logic.

Click through for an explanation of the function, as well as several examples of how it works.

Leave a Comment

Sideways Recursion in DAX Calculation Groups

Marco Russo and Alberto Ferrari’s example goes sideways:

DAX calculation items do not provide full recursion. However, a limited form of recursion is available, known as sideways recursion. We describe this complex topic through examples. Let us start by understanding what recursion is and why it is essential to discuss it. Recursion may occur when a calculation item refers to itself, resulting in an infinite loop within the application of calculation items (read the linked article in case you are not familiar with the concept of “application”, which is different from “execution”). Let us elaborate on this.

Read on for a demonstration of the principle. I haven’t dug into the topic, but I was curious because I’d never heard of “sideways recursion” before. It turns out that there’s some discussion of it in the DAX community and there was something known as Simpson’s sideways recursions from the 1980s, but I’m not sure if that’s the same thing.

Leave a Comment

Recommendations around SUMMARIZECOLUMNS

Marco Russo and Alberto Ferrari share some thoughts:

SUMMARIZECOLUMNS is the most widely-used function in Power BI queries. An important and unique feature of SUMMARIZECOLUMNS is that it determines automatically how to scan the model to produce its result. Indeed, when using SUMMARIZEGROUPBYADDCOLUMNS, or any of the more basic querying functions, developers must declare the source table to perform the grouping, as well as the group-by columns and the measures to add to the result. On the other hand, SUMMARIZECOLUMNS requires only the group-by columns; there is no need to provide the source table, which is the primary ingredient of any query. SUMMARIZECOLUMNS figures out the structure of the result by itself, using a sophisticated algorithm that requires some understanding.

The pair do have a whitepaper available on their premium (paid) service but even the free post contains a lot of detail you’ll want to check out if you use DAX.

Leave a Comment

Tips and Tricks with ALLSELECTED in DAX

Marco Russo and Alberto Ferrari take us through a complicated function:

ALLSELECTED is among the most complex functions in the whole DAX language. ALLSELECTED is the only DAX function that leverages shadow filter contexts. Moreover, ALLSELECTED has a slightly different behavior when used in SUMMARIZECOLUMNS or inside an iterator. Using ALLSELECTED with SUMMARIZECOLUMNS mostly produces the expected result, whereas using ALLSELECTED inside an iterator can produce weird results. Mixing the two techniques is the perfect recipe for a problematic report!

In this article, we briefly describe ALLSELECTED features in both scenarios (SUMMARIZECOLUMNS and iterators), and then we provide the best practices about the function, showing an example where mixing the two behaviors produces an unexpected result.

Read on to learn more.

Comments closed

Month-over-Month and Year-over-Year Calculations in Power BI

Boniface Muchendu does a bit of comparison:

Power BI variance measures are essential for delivering actionable insights through dynamic comparisons like month-over-month (MoM) and year-over-year (YoY) performance. This guide shows how to build flexible, filter-aware DAX measures and apply them within clean, user-friendly visuals to enhance your reports.

Click through to see them in action.

Comments closed

DISTINCT vs VALUES in DAX

Marco Russo and Alberto Ferrari compare two keywords:

When you begin modelling in DAX, DISTINCT and VALUES often appear interchangeable: both return the list of unique values for a column in the current filter context. In a clean development model, they behave the same, so it is easy to pick one at random – or worse, swap between them without thinking.

However, they are not identical. The subtle difference is crucial in production models that may one day contain invalid relationships or bad data

Read on to see how each works and how they differ in practice.

Comments closed

IF Statements and DAX

Marco Russo and Alberto Ferrari talk in hypotheticals:

DAX is a functional language. This means that – no matter how complicated it is – a measure is just ONE function call. Then, functions call other functions, creating the intricacies of a sophisticated DAX expression. However, there is always just one function at the top level. This is, at the same time, beautiful and painful, elegant and complex to understand. It is fair to say that being functional is what makes DAX so fascinating.

However, when a DAX formula is executed, it loses its functional nature. Indeed, in the end it needs to be transformed into a set of simpler queries executed by one of the engines of DAX: either the storage engine or the formula engine. During this step, the function execution is transformed, and it becomes much simpler.

Click through to see how the IF() function works in such a world.

Comments closed

Power BI Model Analysis via INFO Functions in DAX

Reza Rad is leading this interrogation:

There are many DAX functions for covering day-to-day business-related calculations using measures and calculated columns. However, there is also a set of functions that can be helpful to the BI team and developers in gaining insights from the Power BI model itself. The insights can include things such as the number of both-directional relationships, the dependency of the calculations, the list of columns in tables, etc. These functions are in the category of INFO functions in DAX. Let’s see what they are and how they work.

Click through for a list, as well as how you can make use of them.

Comments closed