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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
KristofferAJ
Helper III
Helper III

A circular dependency is detected issue

I have a formula which provides me with an error: "A circular dependency is detected" - and I can't seem to understand why there is a circular dependency.

 

My assumption is the [Time duration fruit sold] which is a measure?

 

Any who can see the issue?

 

Scoring Column =
VAR NCT = CTL[FRUIT]
VAR filteredTable = FILTER ( CTL, NOT ( ISBLANK ( [Time duration fruit sold] ) ) && CTL[FRUIT] = NCT)

RETURN
DIVIDE (
RANKX (
filteredTable,
CTL[Time duration fruit sold],
,
DESC
) - 1,
COUNTROWS ( filteredTable ) - 1
)
 
----
Measure:
Time Duration fruit sold =
VAR dispdate =
MIN( CTL[Site RTE Actual] )
VAR lastsoldthiscountry =
CALCULATE(
MAX( CTL[Site Last Actual] ),
ALL( CTL ),
SUMMARIZE( CTL, CTL[FRUIT], CTL[Country Name] )
)
RETURN
IF(
NOT ( ISBLANK( lastsoldthiscountry ) ) && NOT ( ISBLANK( dispdate ) ),
INT( lastsoldthiscountry - dispdate )
)
1 ACCEPTED SOLUTION
v-kkf-msft
Community Support
Community Support

Hi @KristofferAJ ,

 

Please try these columns.

 

Time Duration = 
VAR dispdate = CTL[Site RTE Actual]
VAR lastsoldthiscountry =
    CALCULATE (
        MAX ( CTL[Site Last Actual] ),
        ALLEXCEPT ( CTL, CTL[FRUIT], CTL[Country Name] )
    )
RETURN
    IF (
        NOT ( ISBLANK ( lastsoldthiscountry ) ) && NOT ( ISBLANK ( dispdate ) ),
        INT ( lastsoldthiscountry - dispdate )
    )
Scoring Column = 
VAR NCT = CTL[FRUIT]
VAR filteredTable =
    FILTER ( CTL, NOT ( ISBLANK ( [Time Duration] ) ) && CTL[FRUIT] = NCT )
RETURN
    DIVIDE (
        RANKX ( filteredTable, [Time Duration],, DESC ) - 1,
        COUNTROWS ( filteredTable ) - 1
    )

vkkfmsft_0-1653448334279.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

4 REPLIES 4
v-kkf-msft
Community Support
Community Support

Hi @KristofferAJ ,

 

Please try these columns.

 

Time Duration = 
VAR dispdate = CTL[Site RTE Actual]
VAR lastsoldthiscountry =
    CALCULATE (
        MAX ( CTL[Site Last Actual] ),
        ALLEXCEPT ( CTL, CTL[FRUIT], CTL[Country Name] )
    )
RETURN
    IF (
        NOT ( ISBLANK ( lastsoldthiscountry ) ) && NOT ( ISBLANK ( dispdate ) ),
        INT ( lastsoldthiscountry - dispdate )
    )
Scoring Column = 
VAR NCT = CTL[FRUIT]
VAR filteredTable =
    FILTER ( CTL, NOT ( ISBLANK ( [Time Duration] ) ) && CTL[FRUIT] = NCT )
RETURN
    DIVIDE (
        RANKX ( filteredTable, [Time Duration],, DESC ) - 1,
        COUNTROWS ( filteredTable ) - 1
    )

vkkfmsft_0-1653448334279.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

AlexisOlson
Super User
Super User

Refer to this article for a detailed explanation of circular dependency in DAX:

https://www.sqlbi.com/articles/understanding-circular-dependencies/

 

The basic issue is that you are trying to define a new column that depends upon a measure that includes the expression ALL ( CTL ), which refers to the entire table you're attempting to add a column to, so it's indirectly referencing itself (since the new column would be part of that entire table). This is just a high-level heuristic explanation though. Please read the article I linked above.

 

The article mentions using ALLEXCEPT as one possible resolution, so you may want to try this modification to the measure:

Time Duration fruit sold =
VAR dispdate =
    MIN ( CTL[Site RTE Actual] )
VAR lastsoldthiscountry =
    CALCULATE (
        MAX ( CTL[Site Last Actual] ),
        ALLEXCEPT ( CTL, CTL[FRUIT], CTL[Country Name] )
    )
RETURN
    IF (
        NOT ( ISBLANK ( lastsoldthiscountry ) ) && NOT ( ISBLANK ( dispdate ) ),
        INT ( lastsoldthiscountry - dispdate )
    )

Thanks for pointing this out. I can see what you mean, and indeed its complicated. And I might consider trying to retrieve this data in another way.

Im trying get the difference days from first sold type FRUIT to latest sold in a specific country.

So in theory the time between first sold ORANGE to the last sold ORANGE in one specific country.

My data would have several different fruits and countries..

daXtreme
Solution Sage
Solution Sage

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors