topic Circular Dependency - Only calculate rows before current row in Desktop
https://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62341#M25673
<P>Hello Power BI Community,</P><P> </P><P>I have an model where we are trying to calculate contract optimization where we take all transactions and compare them against alternatives. When analyzing these alternatives, we look at volume (A) on a MTD and YTD basis by supplier, where the MTD/YTD dates are all dates before the date of the transaction or, alternatively, the RowIndex before the transaction's RowIndex. Then, after analyzing A, if conditions are met (B) the report will say whether the original transaction supplier was the best option or if we should have selected a different supplier (C). Because of the MTD and YTD criteria, if we suggest the supplier is different, we want to track how much volume we are changing from the original supplier to the new supplier (if C is not the original supplier, flag as changed volume (D)). To properly calculate MTD and YTD on the conditions met column (B), we then have to reference A (original volume by supplier) and D (changed volume by supplier) but we only want the totals for all rows before the current row we are trying to calculate. However, we get a circular dependency on a columnar level, because we have a calculation step that looks like A > <U>B</U> > C > D > <U>B</U>. We tried things like CALCULATE(CALCULATE(sum(Volume),Supplier=earlier(Supplier)),RowIndex<earlier(RowIndex) as well as trying to emulate <A href="http://www.powerpivotpro.com/2015/03/how-to-compare-the-current-row-to-the-previous-row-in-power-pivot/" target="_blank">Dany Hoter's LookUpValue solution</A>, but to no avail so far. All described steps are calculated columns as analysis is done at a row (transactional) level. Any insight would be very helpful and appreciate your time,</P><P> </P><P>Shawn</P>Thu, 25 Aug 2016 16:42:42 GMTshawnprodgers2016-08-25T16:42:42ZCircular Dependency - Only calculate rows before current row
https://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62341#M25673
<P>Hello Power BI Community,</P><P> </P><P>I have an model where we are trying to calculate contract optimization where we take all transactions and compare them against alternatives. When analyzing these alternatives, we look at volume (A) on a MTD and YTD basis by supplier, where the MTD/YTD dates are all dates before the date of the transaction or, alternatively, the RowIndex before the transaction's RowIndex. Then, after analyzing A, if conditions are met (B) the report will say whether the original transaction supplier was the best option or if we should have selected a different supplier (C). Because of the MTD and YTD criteria, if we suggest the supplier is different, we want to track how much volume we are changing from the original supplier to the new supplier (if C is not the original supplier, flag as changed volume (D)). To properly calculate MTD and YTD on the conditions met column (B), we then have to reference A (original volume by supplier) and D (changed volume by supplier) but we only want the totals for all rows before the current row we are trying to calculate. However, we get a circular dependency on a columnar level, because we have a calculation step that looks like A > <U>B</U> > C > D > <U>B</U>. We tried things like CALCULATE(CALCULATE(sum(Volume),Supplier=earlier(Supplier)),RowIndex<earlier(RowIndex) as well as trying to emulate <A href="http://www.powerpivotpro.com/2015/03/how-to-compare-the-current-row-to-the-previous-row-in-power-pivot/" target="_blank">Dany Hoter's LookUpValue solution</A>, but to no avail so far. All described steps are calculated columns as analysis is done at a row (transactional) level. Any insight would be very helpful and appreciate your time,</P><P> </P><P>Shawn</P>Thu, 25 Aug 2016 16:42:42 GMThttps://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62341#M25673shawnprodgers2016-08-25T16:42:42ZRe: Circular Dependency - Only calculate rows before current row
https://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62950#M25929
<P><LI-USER uid="6907"></LI-USER></P>
<P> </P>
<P>Your post is a little confusing, could you post any sample or upload the pbix, do mask sensitive data before uploading, you can upload it to Onedrive or any other web storage.</P>Sun, 28 Aug 2016 02:31:00 GMThttps://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62950#M25929Eric_Zhang2016-08-28T02:31:00ZRe: Circular Dependency - Only calculate rows before current row
https://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62951#M25930
<P>Hi Eric,</P><P> </P><P>Thank you for your response. Attached is a model that has two tables. One is the desired outcome, the other is the same table with fact columns and calculated columns trying to get the desired outcome with the circular dependency present. The key field is the Condition Volume Total and the key ability is to be able to include the volume that has met a condition into the net total of volume in the Condition Volume Total field. We can't use measures given that each row must be analyzed individually so unless we created a report table that shows every row (which obviously isn't ideal), we want to accomplish this with calculated columns.</P><P> </P><P>Herer is the One Drive link: <A href="https://1drv.ms/u/s!AgADk3HM2f_cki_o1vMGVr4Dk6Nh" target="_self">https://1drv.ms/u/s!AgADk3HM2f_cki_o1vMGVr4Dk6Nh</A></P><P> </P><P>Really appreciate your time,,</P><P> </P><P>Shawn</P>Sun, 28 Aug 2016 02:46:42 GMThttps://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62951#M25930shawnprodgers2016-08-28T02:46:42ZRe: Circular Dependency - Only calculate rows before current row
https://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62960#M25934
<P><LI-USER uid="6907"></LI-USER></P>
<P> </P>
<P>Thanks for sharing the pbix. The formula looks good. Not sure what did you do, however when I create a new column with the exactly same formula, the circular dependency error doesn't occur and the output seems good.</P>
<P> </P>
<P>For readability, you can format the the DAX formular on <A href="http://www.daxformatter.com/" target="_self">DAX formatter</A>.</P>
<PRE>Condition Volume Total =
[Volume]
+ CALCULATE (
SUM ( Test1[Volume] ),
FILTER (
ALL ( Test1 ),
AND (
Test1[Contract] = EARLIER ( Test1[Contract] ),
Test1[Index.1] < EARLIER ( Test1[Index.1] )
)
)
)
+ CALCULATE (
CALCULATE ( SUM ( Test1[Qualified Volume] ), Test1[Condition Positive] = "Yes" ),
FILTER ( ALL ( Test1 ), Test1[Index.1] < EARLIER ( Test1[Index.1] ) )
)</PRE>
<P> </P>
<P><A href="https://www.sqlbi.com/articles/understanding-circular-dependencies/" target="_self">Understanding Circular Dependencies</A> for your reference.</P>Sun, 28 Aug 2016 05:32:44 GMThttps://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62960#M25934Eric_Zhang2016-08-28T05:32:44ZRe: Circular Dependency - Only calculate rows before current row
https://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62964#M25936
<P>Hi Eric,</P><P> </P><P>Thanks for taking a look. I agree the formula works as is. The central issue I have is I need to reference the total of the formula in the Condition Volume Total column so when I do the Condition Test formula, it is calculating on the desired volume total. Even if I create a new column with the stated functioning formula, when I try to reference is in the Conditional Volume Total column, the circular reference returns and I'm back to square one. Any ideas?</P><P> </P><P>Appreciate your time,</P><P> </P><P>Shawn</P>Sun, 28 Aug 2016 06:29:48 GMThttps://community.powerbi.com/t5/Desktop/Circular-Dependency-Only-calculate-rows-before-current-row/m-p/62964#M25936shawnprodgers2016-08-28T06:29:48Z