Power Query - M "Expression.Error: A cyclic reference" when merging with staging table
<p>I have two tables in my Power Query editor. <code>User</code> and <code>Account</code>.</p>

<p>I am trying to add a column to <code>User</code> that counts how many accounts are owned per user.</p>

<p>To do this I have a staging query called <code>UserAccountCount</code> that references Accounts and performs a group on the User Id. It returns a two column table with <code>User.Id</code> and <code>Count</code>.</p>

<p>I then try to merge and expand the <code>User</code> query on the <code>UserAccountCount</code> but it returns a <code>Expression.Error: A cyclic reference was encountered during evaluation.</code>.</p>

<p>I agree it is cyclical as I have referenced one query in the other. Is  there a way, besides duplication, that I can reference the queries. </p>

<p>I am trying to minimise duplicated code.</p>

<p>I tried to use Table.Buffer so that it would stop evaluating and possibly impact the order that the queries are run.</p>

<p>I should note that the <code>Account</code> table, joins and merges on the <code>User</code> table to bring in the <code>User.Name</code> before it is referenced by <code>UserAccountCount</code>.</p>

<p>Is it bad design to do this in a staging query. Should I just do this using an AddColumn formula?</p>