Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Circular Dependency help

Hi all

 

have a circular dependency error, it was working and i am not sure of the problem.
i added an extra column in the below table for "Region" but my formula's shouldnt care about that considering i just need to determine the max and min of the "Capacity v Usage Difference" column



i have 3 custom columns in the table with formula

IsMax =

 

 

hopefully another set of eyes helps determine what i am doing wrong

thanks

  • edhans's avatar
    edhans
    4 years ago

    They were referencing each other. That is what CALCULATE() does in a Calculated Column. It creates a hidden filter for every column in the table. So when you do the first one, it works. But when you do the second one, it create a filter for the first one, but now the first one creates a filter for the second one. 

    But you don't need CALCULATE here. Here are both column formulas, one Calc Min, and the other Calc Max.

    Calc Min = 
    VAR varCurrentDiff = Data[Capacity v Usage Difference]
    VAR varMin = MIN(Data[Capacity v Usage Difference])
    VAR Result = 
    IF(
        varCurrentDiff = varMin,
        1,
        0
    )
    RETURN
        Result
    
    Calc Max = 
    VAR varCurrentDiff = Data[Capacity v Usage Difference]
    VAR varMax = MAX(Data[Capacity v Usage Difference])
    VAR Result = 
    IF(
        varCurrentDiff = varMax,
        1,
        0
    )
    RETURN
        Result

      You can see my Calc Min/Max are the same as your desired result.

     

     

8 Replies

  • edhans's avatar
    edhans
    Community Champion

    CALCULATE is causing the problem. It is setting a filter for every column. You use it twice and they reference each other.

    You don't need it. ALLSELECTED() is doing nothing here. ALLSELECTED adjusts the filter context, and tables have no filter context, just row context.

    You can just use MAX(table[field]) and it will scan the entire table.

    You probably shouldn't be doing this in a calculated column though. This isn't an Excel spreadsheet. Those values never EVER change after the model loads, so applying filters in a report does nothing to them.

     

    You probably want to use measures, but you'd need to show us what you are doing at the report level. Oddly enough, your DAX code will work as a measure, but it may not return the desired results.

     

    In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
    Calculated Columns vs Measures in DAX
    Calculated Columns and Measures in DAX
    Storage differences between calculated columns and calculated tables
    SQLBI Video on Measures vs Calculated Columns


    How to get good help fast. Help us help you.

    How To Ask A Technical Question If you Really Want An Answer

    How to Get Your Question Answered Quickly - Give us a good and concise explanation
    How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.

    • Anonymous's avatar
      Anonymous
      Not applicable

      edhans 

      i believe it needs to be a column as i want to show the report to have a button
      selecting this button will show which filter the graph to which is closest to capacity (lowest value of "Capacity v Usage Difference")

      but also wish to ensure i could also do the opposite
      so this button was driving by another column

       




      my filter in the button will only show "Closest to Capcity" value

      like i said this was working fine, i changed the table to add another column from the data source and now having this circular problem

      this is the table as it stood with working model