Skip to main content
Microsoft Idea

Power BI

Needs Votes

Relabel/mask the DAX SUMX function as FOREACH

Vote (1) Share
Azarel Howard's profile image

Azarel Howard on 30 Jun 2020 12:06:34

As it stands in PowerBI desktop currently when creating measures, there are several existing aggregation functions, the most commonly used probably being (I'm guessing here) MAX, MIN, and SUM. There's also Count and Count Distinct amongst others. All these functions indicate that DAX has some context as to what data is contained in the lines of the column passed to each of these functions.

So why not a FOREACH function? I know the arguments against having for and while in DAX, they are programmatic and are only really relevant in the context of arrays and PowerBI doesn't have arrays. However, for each is a function of stepping through a given range of data in sequence with no other context, perfect for DAX.

Why do I personally need this? I need to calculate simple interest to date against individual transaction lines that are aggregated, or summed, by a 1 to many relationship from another table.

Why can't you just use a calculated column? I hear you ask. Because the only way to access our data is through the Power BI service connector; we have no direct access to our data and therefore no ability to utilise SQL, M, or other pre-calculated methods. This leaves using DAX in measures as our only possible data manipulation method and without an equivalent to foreach to enforce some context on this sort of calculation we aren't able to to get totals from these calculations.


EDIT:

OK......... after much digging a google search finally made the connection between foreach and sumx...... New proposal, relabel/mask the sumx function as foreach. It does not SUM. It evaluates an expression for each line of the table. Ergo, not a sum operator. It does make it possible to sum the resulting "column" accurately, I guess, but that's about it...