Forum Discussion

MiXiang's avatar
MiXiang
Frequent Visitor
2 years ago
Solved

Need Help in Resolving Circular Dependency

I'm seeking assistance in creating a DAX formula within Power BI that can avoid circular dependencies. This challenge arises because my calculation involves recursion, but I'm optimistic that it can be resolved, as my results are accurate up to the sixth month.

Let's delve into the specifics:

1. Variables:
- NP_B: Data sourced from Excel.
- ND_B: Data sourced from Excel.
- NS_B: Data sourced from Excel.

2. Dependency Relationships:
- NP is dependent on the previous values of ND and NS.
- ND relies on ND_B, NP_B, and NP in its calculation.
- NS depends on NP_R and incorporates a percentage.

The crux of the issue lies in circular dependency:
- NP_R is utilized in both ND and NS calculations, creating a loop. This circular dependency is where I require guidance and a workaround solution tailored to Power BI.

In essence, I'm looking for a DAX formula that allows these interdependent variables to coexist without causing circular dependencies within Power BI.

Thanks a lot!!!

The formula for NP ND NS NP_R:

NP = Previous ND+PreviousNS

ND = ND_B * (NP_R/NP_B-1)

NS = (NP_R*)/3

NP_R = NP_B + NP

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi MiXiang ,

    Circular dependencies in Power BI can occur when two or more objects reference each other in a way that Power BI cannot process. Here are some common scenarios and solutions:

    • Calculated Columns Referencing Each Other: If you create two calculated columns that reference each other, you are generating a circular dependency. For example, if Line Margin is computed based on Discount Pct, and Discount Pct is computed based on Line Margin, you have a circular dependency. The solution is to rephrase your code.
    • Context Transition Inside a Calculated Column: If you use CALCULATE in a calculated column, it performs a context transition and makes that column dependent on all the columns in the table. If two such columns exist, they depend on each other, causing a circular dependency. The solution is to restrict the list of columns that the calculated column depends on by using ALLEXCEPT or REMOVEFILTERS and keeping only the table’s primary key.
    • Creating a Relationship Involving a Calculated Column or Table: This can also cause a hidden circular dependency.

    You can review the following links to understand circular dependencies, avoid it and how to fix it when you got the circular dependencies error.

    Understanding circular dependencies in DAX - SQLBI

    Avoiding circular dependency errors in DAX - SQLBI

    How to fix:

    A circular dependency was detected power bi: Easy Fix - YouTube

    Circular Dependency Breaker DAX Functions ️ || How to Fix Circular Dependency in Power BI - YouTube

     

    If the above ones still not help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi MiXiang ,

    Circular dependencies in Power BI can occur when two or more objects reference each other in a way that Power BI cannot process. Here are some common scenarios and solutions:

    • Calculated Columns Referencing Each Other: If you create two calculated columns that reference each other, you are generating a circular dependency. For example, if Line Margin is computed based on Discount Pct, and Discount Pct is computed based on Line Margin, you have a circular dependency. The solution is to rephrase your code.
    • Context Transition Inside a Calculated Column: If you use CALCULATE in a calculated column, it performs a context transition and makes that column dependent on all the columns in the table. If two such columns exist, they depend on each other, causing a circular dependency. The solution is to restrict the list of columns that the calculated column depends on by using ALLEXCEPT or REMOVEFILTERS and keeping only the table’s primary key.
    • Creating a Relationship Involving a Calculated Column or Table: This can also cause a hidden circular dependency.

    You can review the following links to understand circular dependencies, avoid it and how to fix it when you got the circular dependencies error.

    Understanding circular dependencies in DAX - SQLBI

    Avoiding circular dependency errors in DAX - SQLBI

    How to fix:

    A circular dependency was detected power bi: Easy Fix - YouTube

    Circular Dependency Breaker DAX Functions ️ || How to Fix Circular Dependency in Power BI - YouTube

     

    If the above ones still not help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

    How to provide sample data in the Power BI Forum

     

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards