Forum Discussion
Circular dependencies / calendar tables
- Anonymous9 years ago
The problem is all the bi-directional crossfiltering. It's often better to leave the direction as Single on relationships and use the CROSSFILTER() formula only in the measures that absolutely require the Both directionality.
v-chuncz-msft
I'm still a little confused as to why Power BI was ignoring my USERELATIONSHIP syntax and favouring the active relationship instead. At least that's what I felt was happening... Strange behaviour.
Considering that the order and despatch date can be different for every line, it made more sense to do a calculated column so I could calculate the time to completion there too. The invoice table I have has close to 1 million rows for each year so aggregated figures should be quicker at the user end if I have my overall time to completion calculation done for each row already, shouldn't they?
Following your post, I looked up USERELATIONSHIP measures and read through this post from Our Lord Russo: http://www.sqlbi.com/articles/userelationship-in-calculated-columns/
I tried doing this measure, assuming a SUM would work okay... It doesn't seem to split the total value down per order number though:
I'd be interested in knowing what I'm doing wrong in that measure.
---
Marco's blog post reminded me to try LOOKUPVALUE as a calculated column again and that seemed to be the ticket (WorkingDayOrder is still just using RELATED):
So to conclude, I think Anonymous was mostly on the money there. Using single direction filters on all of my date relationships allowed me to use LOOKUPVALUE properly.
Thanks, both of you, for nudging me in the right direction.
USERELATIONSHIP activates an inactive relationship, but it doesn't deactivate an active one. My impression is that the result is that it tries to use both relationships in that case. If I ever need multiple conflicting relationships, I just leave them all inactive and selectively turn them each back on with USERELATIONSHIP. Usually I will create a base measures like...
BaseSales = CALCULATE( SUM(SalesTable[Amount]), USERELATIONSHIP( DateTable[Date], SalesTable[Date] ) ) BasePurchase = CALCULATE( SUM(PurchaseTable[Amount]), USERELATIONSHIP( DateTable[Date], PurchaseTable[Date] ) )
Then I can do things like this:
Widget Sales = CALCULATE( [BaseSales], FILTER( SalesTable, SalesTable[Category] = "Widgets" ) ) Widget Purchases = CALCULATE( [BaseSales], FILTER( PurchaseTable, PurchaseTable[Category] = "Widgets" ) )