SOLVED

Cyclic reference in Power Query - How to avoid?

Copper Contributor

Hi All,

 

So, rather than show a bunch of code and images, I want to try to just explain the problem and see what options there are to deal with it.

I query SQL Server for a list of about 2K employees.  I have a sheet called Previously_Processed with the employee IDs of people who this process has run the month before.  I select 5% at random of the employees read in from SQL Server excluding those already processed (anti join) and create a sheet with those 5% of employees.  I do this for different cuts of employees looked at different ways.  Each builds it's own sheet.  At the end I want to take all the employee IDs from the sheets that are not Previously_Processed and append them together into Previously_Processed (plus whatever employees already exist in it) so that the next month those people will be excluded from processing.

It is at this step that it says "Expression.Error: A cyclic reference was encountered during evaluation.".  But this is exactly what I need.  I want those processed this month to be excluded from processing next month.  Any ideas how to accomplish this?

TY,

Kirt

5 Replies

@Kirtc 

Do I understood correctly you have queries

- database (DB)

- previously proceeds (PP)

- DB excluding PP (DB-PP)

based on the latest set of queries which forms sheets

- Sh1

- Sh 2

 

Finally you create query which appends Sh1, Sh2, ... to PP ?

@Sergei Baklan thank you for your reply.  I think you follow what I am trying to do. 

 

I have multiple DB queries pulling from SQL Server per vice president.  One of the steps in each of those queries is to do an anti-join against the previously processed (PP) sheet to give me only those people that have not been processed.  I want to then add those people to the PP sheet so next month they will not be processed again.

 

I think Excel gives me a "circular reference" error because it feels it cannot guarantee that the query to add people to the PP sheet will happen after the other queries so it believes there is a conflict.

 

Someone out there in Excel-land who does much more Excel coding than I surely has a way to handle this situation that is clever and I have not thought of.  Thank you.

best response confirmed by Kirtc (Copper Contributor)
Solution

@Kirtc 

Maybe if these are steps within same query. I meant you have separate queries. In general it's always good practice to make operations with separate tables as join, combine, etc as separate queries. With that it shall if on final steps you use references, not initial queries.

Thank you Sergei. I was able to get it to work by simply making the anti-joins to the PP table use a connection only to the PP table whereas when I append to the PP table it is actually linked to and updating the table in Excel.

@Kirtc 

Great to know it works, thank you for the update. 

1 best response

Accepted Solutions
best response confirmed by Kirtc (Copper Contributor)
Solution

@Kirtc 

Maybe if these are steps within same query. I meant you have separate queries. In general it's always good practice to make operations with separate tables as join, combine, etc as separate queries. With that it shall if on final steps you use references, not initial queries.

View solution in original post