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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

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

PowerBi_Batman_0-1634251338869.png

i have 3 custom columns in the table with formula

IsMax =
PowerBi_Batman_1-1634251439227.png

 

PowerBi_Batman_3-1634251468976.png

 

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

thanks

1 ACCEPTED SOLUTION

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.

edhans_0-1634518036570.png

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

8 REPLIES 8
edhans
Super User
Super User

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
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

PowerBi_Batman_1-1634255125230.png

 



PowerBi_Batman_0-1634255056650.png


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

PowerBi_Batman_2-1634255349042.png

 

You are giving bits and pieces, and no data to work with. Remember, I know nothing about your project. Can you please share data and your goal? I'll respost the info on how to do that.

 

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.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

hi @edhans 
i appreciate the reply
the date or table is as follows
with the columns in red as my desired output

DateProductServiceRegionTested CapacityCurrent UsageCapacity v Usage DifferenceIs MinIs Max
1/09/2021Product 1Service 1Region 1118800001973899990610100
1/09/2021Product 1Service 1Region 24395600019738994198210101
1/09/2021Product 1Service 2null52800005633456-35345610
1/09/2021Product 1Service 3null1568160022868731339472700
1/09/2021Product 1Service 4null29700000154116441428835600
1/09/2021Product 1Service 5null105600001694191886580900
1/09/2021Product 1Service 6null4395600056921973826380300
1/09/2021Product 1Service 7null105600001550133900986700



essentially i want to mark the isMin column of which item in the "Capacity v Usage Difference" column is the lowest figure

and then i wish to do the opposite in isMax column of which item is the largest figure

from there i wish to use a dynamic filter(which i can do on another column) on the report so if i select it, it will show the lowest figure row in the related graphs and tables


being a measure this will not allow the graph to filter, so i need the IsMin and isMax to be columns so i then can filter on each of those dynamically.

prior the isMin formula was giving me the error, then all of a sudden it changed to the isMax formula. i cannot tell where the circular dependency is coming from as the formulas do not reference each other. 

 

 

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.

edhans_0-1634518036570.png

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

thanks

that worked

 

i also found that if i change part of my formula (possibly by luck using allexcept) it worked as desired, but i think your method is a bit more robust

Is Min = 

VAR minValue =
CALCULATE ( MIN ( 'Difference Table'[Capacity v Usage Difference] ), ALLEXCEPT('Difference Table','Difference Table'[Capacity v Usage Difference] ))
VAR currentValue =
MIN( 'Difference Table'[Capacity v Usage Difference] )
RETURN
IF ( currentValue = minValue, 1 , 0 )

You are manipulating the filter context that CALCULATE applies with ALLEXCEPT, so you told it to remove filters from everything except the difference column. Therefore CALCULATE doesn't create a filter for every column, and then doesn't create the circular reference. 

But as you can see in my formula, you don't need calculate at all. Create a new column and just put =MAX('Difference Table'[Capacity v Usage Difference]) in it and hit ok. It will be the same value on every row, whatever the MAX value is for the 'Difference Table'[Capacity v Usage Difference] column. Put SUM('Difference Table'[Capacity v Usage Difference]). Same thing.

Now put CALCULATE(SUM('Difference Table'[Capacity v Usage Difference])

Now each row will be unique, and the same value as if you had just put ='Difference Table'[Capacity v Usage Difference] (unless any of the rows are 100% identical)

Study up on context transition to really understand how this works. Chapters 4 and 5 of the Definitive Guide to DAX will really help here. I've read those two chapters dozens of times. So much depth there.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

@edhans 

thanks for the added info. the calculated usage was driven from another post i did a while back, good to know that there are alternatives and i have something to work on

 

thanks

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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