cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
arozaki
Level: Powered On

How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

I am using PowerApps to create a small app which contains two comboboxes, which filter information that are being displayed on a data table and come from an excel sheet called Table. More specifically, my first combobox is called ColorCombo and displays distinct values, which come from the column Color of the sheet Table and the second combobox is called SizeCombo and displays distinct values that are contained on the column Size of the Table

My goal is to filter the information of the one combobox depending on the selection of the other combobox.

For instance, I have the colors : [Red, Blue,Green] listed on the ColorCombo and the sizes: [32,34,36] listed on the SizeCombo. If the red color is only available on size 32 then when I select the red option on the colorcombo I want to only see the number 32 on the SizeCombo and if the size 32 is available on green and blue color then when I select it on the SizeCombo I want to only see the options green and blue on the ColorCombo. The code I have so far is:

Sort(Distinct(Filter(Table, If(CountRows(ColorCombo.SelectedItems) = 0,true, 
Size in SizeCombo.SelectedItems)),Color),Result,Ascending)

which works ok for the colorcombo. When I add the same statement for the SizeCombo as well though, I get an circular reference error. This is the statement I input:

Sort(Distinct(Filter(Table, If(CountRows(SizeCombo.SelectedItems) = 0,true, 
Color in ColorCombo.SelectedItems)),Size),Result,Ascending)

I understand that this is happening because the selection of the comboboxes are depending on each other recursively, so this happens to prevent an infinite loop, but how could I solve this? I appreciate any help you can provide, since I have been trying to find a solution to it since a long time.

6 REPLIES 6

Re: How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

One way that I have broken Infinite loops in the past is to insert a timer into the loop. For example, rather than the final dropdown in the loop refrencing the first, It activates a timer with a duration of 1 millisecond which then on timer end will reference the priamry dropdown

 

Hope this helps

nathanpsmith
Level: Powered On

Re: How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

You can do this quite easily using collections, as long as you don't require users to be able to select multiple sizes or multiple colors at a time.

Three controls:

  • InitializeButton
  • ComboBox_Colors
  • ComboBox_Sizes

InitializeButton.OnSelect =

/*
In this example:
* Red is available in 32, 34 and 36
* Green is available in 32 and 34
* Blue is available in 36 only
*/

ClearCollect(sc1_Colors,
    {Color_ID: 1, ColorName: "Red"},
    {Color_ID: 2, ColorName: "Green"},
    {Color_ID: 3, ColorName: "Blue"}
);

ClearCollect(sc1_Sizes,
    {Size_ID: 1, SizeName: "32"},
    {Size_ID: 2, SizeName: "34"},
    {Size_ID: 3, SizeName: "36"}
);

ClearCollect(sc1_ColorSizes,
    {ColorSize_ID: 1, Color_ID: 1, Size_ID: 1},
    {ColorSize_ID: 2, Color_ID: 1, Size_ID: 2},
    {ColorSize_ID: 3, Color_ID: 1, Size_ID: 3},
    {ColorSize_ID: 4, Color_ID: 2, Size_ID: 1},
    {ColorSize_ID: 5, Color_ID: 2, Size_ID: 2},
    {ColorSize_ID: 6, Color_ID: 3, Size_ID: 3}
);

ClearCollect(sc1_SplitTable, sc1_ColorSizes)

ComboBox_Colors.Items =

Filter(sc1_Colors, Color_ID in sc1_SplitTable.Color_ID)

ComboBox_Sizes.Items =

Filter(sc1_Sizes, Size_ID in sc1_SplitTable.Size_ID)

ComboBox_Colors.OnChange =

ClearCollect(
    sc1_SplitTable,
    Filter(
        sc1_ColorSizes,
        If(
            IsEmpty(ComboBox_Colors.SelectedItems),
            true,
            Color_ID in ComboBox_Colors.SelectedItems.Color_ID
        )
    )
)

ComboBox_Sizes.OnChange =

ClearCollect(
    sc1_SplitTable,
    Filter(
        sc1_ColorSizes,
        If(
            IsEmpty(ComboBox_Sizes.SelectedItems),
            true,
            Size_ID in ComboBox_Sizes.SelectedItems.Size_ID
        )
    )
)

 Or see the bottom screen of the attached file for an example.

Community Support Team
Community Support Team

Re: How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

Hi @arozaki ,

Based on the issue that you mentioned, I think you have faced a Circular Reference Error within your app.

 

Currently, within PowerApps, a property could not reference itself or other properties affected by its value. As an alternative solution, I think a temporary variable could achieve your needs.

 

I have made a test on my side, please take a try with the following workaround:

Set the Items property of the ColorCombo to following:

Sort(
Distinct(Filter(Table, If(CountRows(ColorCombo.SelectedItems) = 0,true, Size in SizeCombo.SelectedItems)), Color),
Result,
Ascending
)

Set the OnChange property of the ColorCombo to following:

ClearCollect(
              CurrentSelectedColor,
ColorCombo.SelectedItems )

Set the Items property of the SizeCombo to following:

Sort(
Distinct(
Filter(
Table,
If(CountRows(SizeCombo.SelectedItems) = 0, true, Color in CurrentSelectedColor)
),
Size
),
Result,
Ascending
)

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
arozaki
Level: Powered On

Re: How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

Hey there @v-xida-msft , thanks for your answer! I tried your code but I get the same error, that is that it creates a circular reference between properties. Does it work for you?

arozaki
Level: Powered On

Re: How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

Hey @MatthewInwards thanks so much for your answer! Do you maybe have an example of this? It would really help me understand better 

Community Support Team
Community Support Team

Re: How can I handle circular reference error in powerapps when trying to filter selections of two comboboxes depending on each other?

Hi @arozaki ,

Could you please share a screenshot about your issue?

 

Currently, I could not reproduce your issue on my side. Based on the issue that you mentioned, I think the variable could achieve your needs.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.