What Should You Put Where the Table Belongs in the New Visual Calculations? – A Complete Understanding of the ROWS() Function
When you first start using the new Visual Calculations feature in Power BI, you will surprisingly run into a bottleneck at the very beginning. This occurs precisely when attempting to deploy iterator functions such as SUMX, AVERAGEX, MAXX, and FILTER.
Code that we used to take completely for granted in standard DAX suddenly stops working.
SUMX(
Sales,
Sales[Qty] * Sales[Price]
)
In a traditional measure, you simply needed to place the Sales table into the first argument. In a Visual Calculation, however, the exact moment you input a table name, an error is triggered.
Initially, I assumed I was simply mistaken about the syntax. However, after days of testing various scenarios, I realized something fundamental: Visual Calculations operate on an entirely different paradigm from traditional DAX.
Today, based on the trial and error I personally experienced, I would like to answer the question: "What exactly should be placed in the first argument of SUMX?"
1. Example Data
Let us assume a simple dataset as shown below.
f_Sales Table
| Year | Month | Category | Sales |
|---|---|---|---|
| 2024 | 1 | Coffee | 100 |
| 2024 | 1 | Tea | 200 |
| 2024 | 1 | Juice | 150 |
| 2025 | 1 | Coffee | 130 |
| 2025 | 1 | Tea | 260 |
| 2025 | 1 | Juice | 180 |
Next, we create a single measure:
Total Sales = SUM(‘f_Sales’ [Sales])
Following this, a Matrix visualization is generated as shown below.
2. The Traditional DAX Paradigm
In a traditional measure, SUMX always iterated through a specific table.
That is, the architecture followed this explicit sequence:
↓
Iterate row by row
↓
Perform evaluation
Consequently, the very first question when writing a SUMX expression was always: "Which table am I going to iterate through?"
3. The Shift in Paradigm for Visual Calculations
Visual Calculations do not directly traverse the underlying data model. Instead, they treat the exact results currently visible on the screen as a single virtual table.
If you attempt to create a new Visual Calculation named Total By SUMX on the table above and place an equivalent measure into the calculation, an error occurs stating that the 'f_Sales' table cannot be found.
[Link] – Creating a New Visual Calculation
Therefore, instead of referencing a model table like 'f_Sales', you must now reference the specific set of rows rendered on the screen.
4. Enter ROWS()
The function that represents the set of rows currently displayed on the screen within a Visual Calculation is ROWS().
For example, if you write the expression:
Total By SUMX = SUMX( ROWS(), [Total Sales])
The ROWS() function will iterate through the Coffee, Tea, and Juice rows currently visible on the screen one by one.
The evaluation process unfolds as follows:
- Coffee → 130
- Tea → 260
- Juice → 180
- Total: 570
5. The One Formula to Remember
1) Traditional DAX
- SUMX( TableName, Expression )
2) New Visual Calculation
- SUMX( ROWS(), Expression )
In short, whereas traditional DAX iterated over a "table within the data model," a Visual Calculation iterates over the "rows currently visible on the screen."
6. Wrapping up
When using Visual Calculations for the first time, the most frequently asked question is this: "I want to use SUMX or FILTER, but what should I put in place of the table?"
The answer is remarkably straightforward: simply use ROWS(), which represents the rows currently displayed on the screen.
While traditional DAX iterated through the tables of a data model, the new Visual Calculations feature iterates through the row set of the visualization currently being viewed by the user.
Therefore, when utilizing iterator functions (X-functions) within a Visual Calculation, you only need to remember this single sentence:
The moment you grasp this concept, most iterator functions—such as SUMX, AVERAGEX, MAXX, and FILTER—will begin to appear far more intuitive.
Comments
Post a Comment