Forum Discussion
Circular dependency error in Measures
- Anonymous1 year ago
Hi Rozers ,
The circular dependency error occurs because the measures COGS Value at the End of the Month and COGS Value at the Start of the Month are referencing each other. This creates a loop where each measure depends on the other, making it impossible for Power BI to calculate the values.
To resolve this, you need to break the circular reference. One way to do this is by using a different approach to calculate the COGS Value at the Start of the Month without directly referencing COGS Value at the End of the Month.
So you can use these DAX codes below:
PrevMonthCOGS = CALCULATE( [COGS Value at the End of the Month], FILTER( ALL(Dim_Date), Dim_Date[YearMonth] = MAX(Dim_Date[YearMonth]) - 1 ) )COGS Value at the Start of the Month = VAR JanCOGS = SUM(COGS[start of the month cogs]) RETURN IF( MAX(Dim_Date[YearMonth]) = 202301, JanCOGS, [PrevMonthCOGS] )COGS Value at the End of the Month = VAR Summary = SUMMARIZE( product, product[product_code], product[product_name], "RequiredQty", SUM(po[required_quantity]), "PlannedQty", SUM(po[planned_quantity]), "Wtavg", [Wt Avg PP], "Stock", [Starting_stock], "PrevMonthCOGS", [PrevMonthCOGS] ) VAR Cal = SUMX( Summary, DIVIDE( ([Stock]*[PrevMonthCOGS]) + ([Wtavg]*[RequiredQty]), ([Stock] + [RequiredQty]) ) ) RETURN CalIf this is not what you want either, please provide relevant example data for better research.
Best Regards
Yilong Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for the solution, BeaBF!
Instead of using a calculated column, I want to achieve this using measures only.