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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
adentler
Advocate I
Advocate I

Expression.Error: A cyclic reference was encountered during evaluation.

Hi all.. I am wondering if any of you amazing POWER BI Power Query Users can help me understand better the Expression.Error: A cyclic reference was encountered during evaluation.

 

I am trying to add a Custom Column during the transform process, immediately after establishing my source from a SQL query.

The column I am trying to add is to evaluate Table 1 [Date Column] between Table 2 [Start Date] and Table 2 [End Date].

 

I am using the following code:

 

Table.AddColumn(
    Table1,
    "Contract Year",
    each if [posting_date] >= Table2[Start Date] and [posting_date] <= Table2[End Date] 
         then Table2[Contract Year]
         else null
)

 

I cannot determine:

1. Is the "cyclic" in reference to the code?

 

Things to know:

 

There are no relationships established between my main table to any other table. 

There are no additional calculated, or other, columns that have been added at this point. 

 

In my mind, this table is importing from a database clean, fresh, untouched data, so there should be no cyclic reference to anything else.  I also realize that I may have a complete lack of understanding of this error. PLEASE HELP!! (Still learning... )

 

FYI - I have attempted to create this column using "Merge Queries", but do not see the option to change the Join Kind to a Custom Join that will allow the BETWEEN dates functionality that I need.

3 ACCEPTED SOLUTIONS
jgeddes
Super User
Super User

The error could be thrown if Table2 has Table1 as its source (or is referenced). 

EG.

Table1

jgeddes_0-1757092104747.png

Table2

Is created by referencing selecting rows from Table1

= Table.SelectRows(Table1, each ([Contract] = "ABC"))

jgeddes_1-1757092197379.png

Trying to add a column to Table1 with Table2 as criteria throws the cyclic reference error.

jgeddes_2-1757092271564.png

If I had a third table that was not based on Table1

jgeddes_3-1757092341280.png

The cyclic error would not appear if Table3 is used as criteria. In this case I do get a type comparison error (which you will likely get as it appears you are comparing a date in Table1 to the list of dates from Table2)

jgeddes_4-1757092451112.png

To clear the type comparison error you would need to select a single value from your Table2 as opposed to the list.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

To be clear, fixing the list issue will not get rid of the cyclic problem. The cyclic problem can only be fixed by correcting the table reference.

But as far as list values go...
Consider Table1->

jgeddes_0-1757094092384.png

and Table2 ->

jgeddes_1-1757094114722.png

If we want to get a single date value from Table2 into Table1 where the Categories match it could look like this...
In Table1 add a custom column...

jgeddes_2-1757094295763.png

This returns the list of Dates from Table2 where the Category matches.

You need to know which value from the list you need. Do you need the max date?

jgeddes_3-1757094385434.png

Do you need the first date? (Using List.First)

jgeddes_4-1757094426114.png

OR (Using the 0th index value of the list)...

jgeddes_5-1757094458607.png

Understanding and using lists opens up a whole new level of options in your M code. 
Here is the MS Learn document for List Functions.

https://learn.microsoft.com/en-us/powerquery-m/list-functions 

Hope this helps.







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

Omid_Motamedise
Super User
Super User

Why the cyclic reference error happens:

In Power Query, Table2[Start Date] does not mean “for each row of Table2, grab Start Date”.

Instead, it returns the entire column as a list.

When you write it this way inside Table.AddColumn, PQ doesn’t know which row of Table2 you mean → it ends up trying to self-reference while evaluating, which triggers the cyclic reference error.

 

Since what you want is a between join (posting_date falls between [Start Date] and [End Date] in Table2), you can’t do it directly in Table.AddColumn. Instead you need to use a cross join + filter

Add a dummy column to both tables (e.g. column with value = 1).

Merge queries on that dummy column → you’ll get all combinations of Table1 × Table2.

Expand Table2.

Add a custom column with your condition:
if [posting_date] >= [Start Date] and [posting_date] <= [End Date]
then [Contract Year] else null

Filter out nulls if you want only matching rows.

This works well if Table2 is small (e.g. contract periods table with dozens/hundreds of rows, not millions).

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

View solution in original post

7 REPLIES 7
adentler
Advocate I
Advocate I

@jgeddes @Omid_Motamedise  Thank you both for your guidance and assistance on this item. I have a better understanding of what is going on and am still working through this issue. I am going to read through the links provided and re-read (probably several times!) your comments. For now, I am going to close this item as resolved in hopes that others will also benefit from the information you both have provided.

V-yubandi-msft
Community Support
Community Support

Hi @adentler ,

Thank you for engaging with the Microsoft Fabric Community.The @jgeddes  explanation about the cyclic reference issue is accurate. You may also find these related discussions useful, as they cover similar cases and offer possible solutions.

Solved: Expression.Error: A cyclic reference was encounter... - Microsoft Fabric Community

Solved: Suddenly "Expression.Error: A cyclic reference was... - Microsoft Fabric Community

These threads include more examples and methods that could help you understand and address the issue.

Thanks for your response @jgeddes @Omid_Motamedise 

 

Regards,
Yugandhar.

Omid_Motamedise
Super User
Super User

Why the cyclic reference error happens:

In Power Query, Table2[Start Date] does not mean “for each row of Table2, grab Start Date”.

Instead, it returns the entire column as a list.

When you write it this way inside Table.AddColumn, PQ doesn’t know which row of Table2 you mean → it ends up trying to self-reference while evaluating, which triggers the cyclic reference error.

 

Since what you want is a between join (posting_date falls between [Start Date] and [End Date] in Table2), you can’t do it directly in Table.AddColumn. Instead you need to use a cross join + filter

Add a dummy column to both tables (e.g. column with value = 1).

Merge queries on that dummy column → you’ll get all combinations of Table1 × Table2.

Expand Table2.

Add a custom column with your condition:
if [posting_date] >= [Start Date] and [posting_date] <= [End Date]
then [Contract Year] else null

Filter out nulls if you want only matching rows.

This works well if Table2 is small (e.g. contract periods table with dozens/hundreds of rows, not millions).

 

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h
jgeddes
Super User
Super User

The error could be thrown if Table2 has Table1 as its source (or is referenced). 

EG.

Table1

jgeddes_0-1757092104747.png

Table2

Is created by referencing selecting rows from Table1

= Table.SelectRows(Table1, each ([Contract] = "ABC"))

jgeddes_1-1757092197379.png

Trying to add a column to Table1 with Table2 as criteria throws the cyclic reference error.

jgeddes_2-1757092271564.png

If I had a third table that was not based on Table1

jgeddes_3-1757092341280.png

The cyclic error would not appear if Table3 is used as criteria. In this case I do get a type comparison error (which you will likely get as it appears you are comparing a date in Table1 to the list of dates from Table2)

jgeddes_4-1757092451112.png

To clear the type comparison error you would need to select a single value from your Table2 as opposed to the list.

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank  you for this explanation. I agree that it is more likely the fact that I am comparing a date in Table1 to the list of dates from Table2. Would it be possible to use the List.PositionOf  in this situation (evaluating between 2 dates)? I did another Custom Column on a different table that evaluated only 1 criteria using this but am not sure how to translate it to the 2 dates evaluation. My other column was coded like this:

 

= Table2[Result]{List.PostitionOf(Table2[Category],[Category])}

 

I understand that with the above code I am looking at only 1 search criteria and it is a 1 for 1. I am struggling to get to where I need in order to transform another column where I bring the category over based  evaluating the dates.

 

To be clear, fixing the list issue will not get rid of the cyclic problem. The cyclic problem can only be fixed by correcting the table reference.

But as far as list values go...
Consider Table1->

jgeddes_0-1757094092384.png

and Table2 ->

jgeddes_1-1757094114722.png

If we want to get a single date value from Table2 into Table1 where the Categories match it could look like this...
In Table1 add a custom column...

jgeddes_2-1757094295763.png

This returns the list of Dates from Table2 where the Category matches.

You need to know which value from the list you need. Do you need the max date?

jgeddes_3-1757094385434.png

Do you need the first date? (Using List.First)

jgeddes_4-1757094426114.png

OR (Using the 0th index value of the list)...

jgeddes_5-1757094458607.png

Understanding and using lists opens up a whole new level of options in your M code. 
Here is the MS Learn document for List Functions.

https://learn.microsoft.com/en-us/powerquery-m/list-functions 

Hope this helps.







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Your explanation and time provided are very much appreciated. I will review all that you provided and also the link about list functions.  I think both will help me gain understanding. 

 

I am actually not trying to pull the first date or the max date.. instead, I am trying to get the Contract Year. My reference table Table 2 is structured as follows:

 

Acct CodeContract YearStart DateEnd DateCost Center
00123AAYear 107/01/202406/30/20251111
10123AAYear 207/01/202506/30/20261111
00223ABYear 107/01/202406/30/20252222
10223ABYear 207/01/202506/30/20262223

 

As you can see, Cost Center and Acct Code have a many to many correlation but are distinguished by the Contract Year.

 

Table 1 is structured as follows:

 

Cost CenterDoc Noposting_dateAmount
1111ABC-12307/5/20251000.00
1111ABC-00503/15/20242000.00
2222ABB-10505/02/20243000.00
2222ABC-20009/05/20251500.00

 

Using DAX, I was able to add a calculated column after import. However, what I have been racking my brain is how to do it during the transform procress (and avoid the cyclic reference, hence my original post you were kind enough to respond to).

 

I only am adding my 2 source tables as reference in hopes I make it clearer (more for my purposes I think). 

 

I was hoping to end up with a Table 1 that looks like this:

 

Cost CenterDoc Noposting_dateAmountContract Year
1111ABC-12307/5/20251000.00Year 2
1111ABC-00503/15/20242000.00Year 1
2222ABB-10505/02/20243000.00Year 1
2222ABC-20009/05/20251500.00Year 2

 

I can see by your explanation that the List of Start Date/ End Date may be the issue and I need to start there. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors