Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
GunnerJ
Post Patron
Post Patron

Help with Circular Dependency

First I want to say that I've looked through several of the other post related to cirular dependency but they haven't helped me correct this issue. The two calculated columns below create a circular dependency. "Last SO" was created first and I'd prefer to not change it if at all possible. "Last Count" is looking at a cumulative total and trying to show what the value was before the current row where account is the same and the date came before. Is there some kind of filter magic we can use to keep the same functionality but to get rid of the error?

 

 

Last SO =
CALCULATE(LASTNONBLANK('SO Attrition'[BI_SO_TYPE_CD],1),FILTER('SO Attrition', 'SO Attrition'[BI_ACCT] = EARLIER('SO Attrition'[BI_ACCT]) && 'SO Attrition'[NEEDED_DT] < EARLIER('SO Attrition'[NEEDED_DT]) && 'SO Attrition'[SRV_MAP_LOC] = EARLIER('SO Attrition'[SRV_MAP_LOC])&& 'SO Attrition'[BI_SO_TYPE_CD] <> EARLIER('SO Attrition'[BI_SO_TYPE_CD])))

 

Last Count =
CALCULATE(LASTNONBLANK('SO Attrition'[DISC running Total],1),FILTER('SO Attrition', 'SO Attrition'[BI_ACCT] = EARLIER('SO Attrition'[BI_ACCT]) && 'SO Attrition'[NEEDED_DT] < EARLIER('SO Attrition'[NEEDED_DT])))
1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

I think you can avoid this by eliminating the context transition induced by CALCULATE.

 

See if these versions work any better:

Last SO =
VAR FilteredTable =
    FILTER (
        'SO Attrition',
        'SO Attrition'[BI_ACCT] = EARLIER ( 'SO Attrition'[BI_ACCT] )
            && 'SO Attrition'[NEEDED_DT] < EARLIER ( 'SO Attrition'[NEEDED_DT] )
            && 'SO Attrition'[SRV_MAP_LOC] = EARLIER ( 'SO Attrition'[SRV_MAP_LOC] )
            && 'SO Attrition'[BI_SO_TYPE_CD] <> EARLIER ( 'SO Attrition'[BI_SO_TYPE_CD] )
    )
RETURN
    MAXX ( FilteredTable, 'SO Attrition'[BI_SO_TYPE_CD] )
Last Count =
VAR FilteredTable =
    FILTER (
        'SO Attrition',
        'SO Attrition'[BI_ACCT] = EARLIER ( 'SO Attrition'[BI_ACCT] )
            && 'SO Attrition'[NEEDED_DT] < EARLIER ( 'SO Attrition'[NEEDED_DT] )
    )
RETURN
    MAXX ( FilteredTable, 'SO Attrition'[DISC running Total] )

 

It's possible to get it to work with CALCULATE but easier to mess up, especially if you're not comfortable with context transition concepts.

View solution in original post

5 REPLIES 5
AlexisOlson
Super User
Super User

I think you can avoid this by eliminating the context transition induced by CALCULATE.

 

See if these versions work any better:

Last SO =
VAR FilteredTable =
    FILTER (
        'SO Attrition',
        'SO Attrition'[BI_ACCT] = EARLIER ( 'SO Attrition'[BI_ACCT] )
            && 'SO Attrition'[NEEDED_DT] < EARLIER ( 'SO Attrition'[NEEDED_DT] )
            && 'SO Attrition'[SRV_MAP_LOC] = EARLIER ( 'SO Attrition'[SRV_MAP_LOC] )
            && 'SO Attrition'[BI_SO_TYPE_CD] <> EARLIER ( 'SO Attrition'[BI_SO_TYPE_CD] )
    )
RETURN
    MAXX ( FilteredTable, 'SO Attrition'[BI_SO_TYPE_CD] )
Last Count =
VAR FilteredTable =
    FILTER (
        'SO Attrition',
        'SO Attrition'[BI_ACCT] = EARLIER ( 'SO Attrition'[BI_ACCT] )
            && 'SO Attrition'[NEEDED_DT] < EARLIER ( 'SO Attrition'[NEEDED_DT] )
    )
RETURN
    MAXX ( FilteredTable, 'SO Attrition'[DISC running Total] )

 

It's possible to get it to work with CALCULATE but easier to mess up, especially if you're not comfortable with context transition concepts.

@AlexisOlson 

That worked in getting rid of the circular dependency for those columns! Sadly one bit of bad news is that it seems to have passed the dependency onto another column. "DISC Running Total" is a cumulative sum working on an account level. Its saying its dependency is related to "Last Count" which you've provided. I know "Last Count" literally references it but I'm unsure how to make a cumulative total without calculate. Any help?

DISC running Total =
VAR LastNeededDt = CALCULATE(MAX('SO Attrition'[NEEDED_DT]))
VAR countOfDISC =
CALCULATE(
SUM('SO Attrition'[add or disc]),
FILTER(
ALLSELECTED('SO Attrition'),
'SO Attrition'[NEEDED_DT] <= LastNeededDt),
'SO Attrition'[BI_ACCT] = EARLIER('SO Attrition'[BI_ACCT]))
Return countOfDISC



You could rewrite this one like I did with the others.

 

Here's a CALCULATE version too that I think should work:

 

DISC running Total =
CALCULATE (
    SUM ( 'SO Attrition'[add or disc] ),
    ALLEXCEPT ( 'SO Attrition', 'SO Attrition'[BI_ACCT] ),
    'SO Attrition'[NEEDED_DT] <= EARLIER ( 'SO Attrition'[NEEDED_DT] )
)

 

@AlexisOlson it worked! thank you! 

You referenced Context transitions. Just for future knowledge do you have a best source to get more familiar?

I included a link to an article upon my first mention.

 

Here's that link again along with another more recently written article:
https://www.sqlbi.com/articles/understanding-context-transition/

https://www.burningsuit.co.uk/context-transition-where-the-row-context-becomes-a-filter-context/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.