Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

How to Overcome a Circular Dependency was Detected

Hi All,

 

This is my first time facing an issue like this. Basically I am attempting to perform the computation below:

 

My Measures (NB: All my measures are in the table MeasureFuel):

 

daily_closing_useful_stock = 'MeasureFuel'[daily_closing_global_fuel_stock] - sum(Parameters[Dead stock (Liter)]) /* Final Result */

 

Intermediate results

 

daily_closing_global_fuel_stock = 'MeasureFuel'[opening_global_fuel_stock] + sum('Daily Input'[Daily Delivery (Liter)]) - sum('Daily Input'[Daily Consumptions (Liter)])

 

Intermediate results

 

opening_global_fuel_stock = if ('MeasureFuel'[daily_closing_fuel_stock_pd] <> 0, 'MeasureFuel'[daily_closing_fuel_stock_pd], sum(Parameters[Opening Global fuel Stock (Liter)])

 

Intermediate results

 

daily_closing_global_fuel_stock_pd = CALCULATE( 'MeasureFuel'[daily_closing_global_fuel_stock], PREVIOUSDAY(DimDate[Date]))

 

My issue is this: When I try to save the measure opening_global_fuel_stock, i get the error "A circular dependency was detected"

 

How can I fix this??

5 Replies

  • edhans's avatar
    edhans
    Icon for Community Champion rankCommunity Champion

    Are you sure those are measures? Some of those look like calculated columns, and it is easy to get into a circular dependency in a calculated column.

     

    You can greatly avoid much of this by calculating those columns in Power Query and bring them in there if possible. If not, you have to understand how CALCULATE() actually uses every column behind the scenes to do its work when used in a calculated column, so if the calculated column references columns A and B, it really references all columns when determining row context, then you do another calculated column with CALCULATE, it references all existing columns, but your first column you created now refrences this second one too, and you get a circular dependency. It can get complex.

     

    You can read more details here, or you can see Chapter 5 of "The Definitive Guide to DAX 2nd Edition" if you really want to dig in to this.

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi edhans ,

       

      Thanks for your input

       

      Those are measures. All my measures are in the table MeasureFuel.

       

      Regards,

       

      Divo

      • edhans's avatar
        edhans
        Icon for Community Champion rankCommunity Champion

        Ok. The standard way to refer to measures is just [MeasureName] with no table. Measures can be anywhere. Unlike TableName[FieldName] would refer to a specific field in a table. That is why I thought those were calculated columns. Table names in formulas refer to specific fields.

         

        [daily_closing_global_fuel_stock_pd] (1) is referring to [daily_closing_global_fuel_stock] (2) and (3), which is referring to [opening_global_fuel_stock] (4) and (5), which is referring back to [daily_closing_global_fuel_stock].

         

        That is where your circular reference error is coming from I think.

         

         

  • v-xicai's avatar
    v-xicai
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    There is a good description for circular dependencies: https://www.sqlbi.com/articles/understanding-circular-dependencies/.

     

    It does not allow to have two calculated columns that contain measures that are also based on that table.   As a workaround, you may try to convert these into measures instead of column.

     

    You can refer to the similar case: "A circular Dependency was detected" error while creating a calculated column.

     

    Best Regards,

    Amy

     

    Community Support Team _ Amy

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-xicai's avatar
    v-xicai
    Icon for Community Support rankCommunity Support

    Hi  Anonymous ,

     

    Does that make sense? If so, kindly mark the proper reply as a solution to help others having the similar issue and close the case. If not, let me know and I'll try to help you further.

     

    Best regards

    Amy

     

    Hi,