Forum Discussion
Row Identifier within Power BI for Desktop (Circular dependencies with the DAX CALCULATE function)
Hi Brian. No, it's not completed yet. It's on our to-do list but it's a relatively little-known feature and we've been prioritizing things requested by more folks. Did you try the index column workaround?
Hi WillT I did try the row ID trick but no luck for my scenario.
Although I've gotten by the issue by defining a measure instead of a calculated column, I thought I'd spell it all out here in case you have any insight.
I am trying to add a calculated column which is in the form Column = CALCULATE ( ....) which I understand from Alberto's post:
"The problem is that any calculated column containing CALCULATE (or a call to any measure, which adds an automatic CALCULATE) creates a dependency from all of the columns of the table."
As a precaustion I deleted all other calculated columns on that table but it didn't help.
The reason I was trying to set it as a calculated column was to bypass a performance issue (30 seconds to calculate as a measure) - i.e.just to calculate it once at report initiation. I've managed to tune the formula such that it runs in 1 second (instead of 30) - ... thanks to Marco for his Optimising DAX Course in London!! so I'm now able to run it as a measure for now.
I suspect I know why I am getting the circular dependency when I try to set it as a calculated column, but I can't for the life of me figure out how to get by it. I think it might be because of the variables I'm using inside the SUMX to materialise certain data early to reduce the number of rows being crunched by my iterators. I think I've isolated the problem to the line that is marked -----YYYY in the code below. I couldn't figure out how to use Alberto's ALLSELECTED work around, and the row ID's didn't work.
It runs in DAX Studio just fine as an ADDCOLUMNS(....) but when I try to add it as a calculated column on my table I get
"A circular dependency was detected: Payments[Column]"
Here's the code. I gave it >4 hours of my life trying to make it work!
Column = CALCULATE(
SUMX (
Payments, /*-----YYYYY Think the problem is here */
VAR MyCurrency =
CALCULATE ( VALUES ( Currency[isocurrencycode] ) )
VAR MyDate = Payments[Payment Date]
VAR FilteredXrateTable =
TOPN (
1,
FILTER (
CALCULATETABLE ( Xrates, Xrates[From] = MyCurrency ),
Xrates[Valid from] <= MyDate
),
Xrates[Valid from], DESC
)
RETURN
Payments[Gross Local]
* CALCULATETABLE ( VALUES ( Xrates[Exch. Rate] ), FilteredXrateTable )
)