cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
toby-at-yell
Level: Powered On

Limit to the number of expressions used when filtering a Collection

I have a Collection (LocalClaims) that is populated from a SharePoint List on the OnVisible property of the Screen. There are around 30 entries that get populated from the SharePoint List successfully.

The Gallery control uses the following formula for it's Items property.

Filter(
    Switch(
        SortSettings.SortBy,
        "SubmittedBy",
        Sort(
            LocalClaims,
            SubmittedBy.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "SubmittedOn",
        Sort(
            LocalClaims,
            SubmittedOn,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ClaimCode",
        Sort(
            LocalClaims,
            ClaimCode,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ApprovedBy",
        Sort(
            LocalClaims,
            LineManagerApprover.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        Sort(
            LocalClaims,
            SubmittedOn,
            Ascending
        )
    ),
     If(
        IsEmpty(ApprovedByFilterComboBox.SelectedItems),
        true,
        LineManagerApprover.DisplayName in ApprovedByFilterComboBox.SelectedItems
    ) &&
    If(
        IsEmpty(StatusFilterComboBox.SelectedItems),
        true,
        ClaimStatus.Value in StatusFilterComboBox.SelectedItems
    ) &&
    SubmittedOn >= DateTimeValue(
        Text(
            FromSubmittedOnFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 00:00:00"
    ) && SubmittedOn <= DateTimeValue(
        Text(
            ToSubmittedByFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 23:59"
    ) &&
    If(
        IsBlank(ClaimCodeFilterTextInput.Text),
        true,
        ClaimCodeFilterTextInput.Text in ClaimCode
    )
)

This works fine, but if I add one more condition in then it will return no records at all

&& If(
        IsEmpty(SubmittedByFilterComboBox.SelectedItems),
        true,
        SubmittedBy.DisplayName in SubmittedByFilterComboBox.SelectedItems
    )

I have tried this by chaining together as one expression and adding as seperate expressions in the Filter function. Also I have tried using different combinations and orders. It's only when I add more than 4 epxressions that it returns no rows.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Limit to the number of expressions used when filtering a Collection

Hi @toby-at-yell,

Currently, there is no official document mentioned about the limits of the number of the expressions userd to filter a Collection.

Please check if there are no records within the records your previous formula returns match the filter condition you added later.

Please also consider take a try to save the records your previous formula returns into another new Collection (e.g. PreCollection), then filter the PreCollection based on the filter condition you added later. Please take a try with the following formula:

ClearCollect(
   PreCollection, 
   Filter(
    Switch(
        SortSettings.SortBy,
        "SubmittedBy",
        Sort(
            LocalClaims,
            SubmittedBy.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "SubmittedOn",
        Sort(
            LocalClaims,
            SubmittedOn,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ClaimCode",
        Sort(
            LocalClaims,
            ClaimCode,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ApprovedBy",
        Sort(
            LocalClaims,
            LineManagerApprover.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        Sort(
            LocalClaims,
            SubmittedOn,
            Ascending
        )
    ),
     If(
        IsEmpty(ApprovedByFilterComboBox.SelectedItems),
        true,
        LineManagerApprover.DisplayName in ApprovedByFilterComboBox.SelectedItems
    ) &&
    If(
        IsEmpty(StatusFilterComboBox.SelectedItems),
        true,
        ClaimStatus.Value in StatusFilterComboBox.SelectedItems
    ) &&
    SubmittedOn >= DateTimeValue(
        Text(
            FromSubmittedOnFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 00:00:00"
    ) && SubmittedOn <= DateTimeValue(
        Text(
            ToSubmittedByFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 23:59"
    ) &&
    If(
        IsBlank(ClaimCodeFilterTextInput.Text),
        true,
        ClaimCodeFilterTextInput.Text in ClaimCode
    )
  )
)

Then add the following formula within the Items property of your Gallery control:

Filter(
     PreCollection,
     If(
        IsEmpty(SubmittedByFilterComboBox.SelectedItems),
        true,
        SubmittedBy.DisplayName in SubmittedByFilterComboBox.SelectedItems
    )
)

then check if there are some records listed within your Gallery control.

In addition, as an alternative solution, please take a try with the following workaround:

Set the OnVisible property of the first screen of your app to following:

ClearCollect(LocalClaims, 'YourSPList')

Set the Items property of the Gallery control to following formula:

Filter(
    Switch(
        SortSettings.SortBy,
        "SubmittedBy",
        Sort(
            LocalClaims,
            SubmittedBy.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "SubmittedOn",
        Sort(
            LocalClaims,
            SubmittedOn,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ClaimCode",
        Sort(
            LocalClaims,
            ClaimCode,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ApprovedBy",
        Sort(
            LocalClaims,
            LineManagerApprover.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        Sort(
            LocalClaims,
            SubmittedOn,
            Ascending
        )
    ),
    SubmittedOn >= DateTimeValue(
        Text(
            FromSubmittedOnFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 00:00:00"
    ) && SubmittedOn <= DateTimeValue(
        Text(
            ToSubmittedByFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 23:59"
    ) &&
    If(
        IsBlank(ClaimCodeFilterTextInput.Text),
        true,
        ClaimCodeFilterTextInput.Text in ClaimCode
    )
)

Set the OnChange property of the ApprovedByFilterComboBox to following:

If(
  !IsEmpty(ApprovedByFilterComboBox.SelectedItems),
  ClearCollect(
       LocalClaims,
       Filter('YourSPList', LineManagerApprover.DisplayName in ApprovedByFilterComboBox.SelectedItems)
   )
)

Set the OnChange property of the StatusFilterComboBox to following:

If(
  !IsEmpty(StatusFilterComboBox.SelectedItems),
  ClearCollect(
       LocalClaims,
       Filter('YourSPList', ClaimStatus.Value in StatusFilterComboBox.SelectedItems)
   )
)

Set the OnChange property of the SubmittedByFilterComboBox to following:

If(
  !IsEmpty(SubmittedByFilterComboBox.SelectedItems),
  ClearCollect(
       LocalClaims,
       Filter('YourSPList', SubmittedBy.DisplayName in SubmittedByFilterComboBox.SelectedItems)
   )
)

then check if the issue is solved.

 

Best regards,

Kris

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.

View solution in original post

2 REPLIES 2
Community Support Team
Community Support Team

Re: Limit to the number of expressions used when filtering a Collection

Hi @toby-at-yell,

Currently, there is no official document mentioned about the limits of the number of the expressions userd to filter a Collection.

Please check if there are no records within the records your previous formula returns match the filter condition you added later.

Please also consider take a try to save the records your previous formula returns into another new Collection (e.g. PreCollection), then filter the PreCollection based on the filter condition you added later. Please take a try with the following formula:

ClearCollect(
   PreCollection, 
   Filter(
    Switch(
        SortSettings.SortBy,
        "SubmittedBy",
        Sort(
            LocalClaims,
            SubmittedBy.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "SubmittedOn",
        Sort(
            LocalClaims,
            SubmittedOn,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ClaimCode",
        Sort(
            LocalClaims,
            ClaimCode,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ApprovedBy",
        Sort(
            LocalClaims,
            LineManagerApprover.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        Sort(
            LocalClaims,
            SubmittedOn,
            Ascending
        )
    ),
     If(
        IsEmpty(ApprovedByFilterComboBox.SelectedItems),
        true,
        LineManagerApprover.DisplayName in ApprovedByFilterComboBox.SelectedItems
    ) &&
    If(
        IsEmpty(StatusFilterComboBox.SelectedItems),
        true,
        ClaimStatus.Value in StatusFilterComboBox.SelectedItems
    ) &&
    SubmittedOn >= DateTimeValue(
        Text(
            FromSubmittedOnFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 00:00:00"
    ) && SubmittedOn <= DateTimeValue(
        Text(
            ToSubmittedByFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 23:59"
    ) &&
    If(
        IsBlank(ClaimCodeFilterTextInput.Text),
        true,
        ClaimCodeFilterTextInput.Text in ClaimCode
    )
  )
)

Then add the following formula within the Items property of your Gallery control:

Filter(
     PreCollection,
     If(
        IsEmpty(SubmittedByFilterComboBox.SelectedItems),
        true,
        SubmittedBy.DisplayName in SubmittedByFilterComboBox.SelectedItems
    )
)

then check if there are some records listed within your Gallery control.

In addition, as an alternative solution, please take a try with the following workaround:

Set the OnVisible property of the first screen of your app to following:

ClearCollect(LocalClaims, 'YourSPList')

Set the Items property of the Gallery control to following formula:

Filter(
    Switch(
        SortSettings.SortBy,
        "SubmittedBy",
        Sort(
            LocalClaims,
            SubmittedBy.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "SubmittedOn",
        Sort(
            LocalClaims,
            SubmittedOn,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ClaimCode",
        Sort(
            LocalClaims,
            ClaimCode,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        "ApprovedBy",
        Sort(
            LocalClaims,
            LineManagerApprover.DisplayName,
            If(
                SortSettings.SortDirection = "Asc",
                Ascending,
                Descending
            )
        ),
        Sort(
            LocalClaims,
            SubmittedOn,
            Ascending
        )
    ),
    SubmittedOn >= DateTimeValue(
        Text(
            FromSubmittedOnFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 00:00:00"
    ) && SubmittedOn <= DateTimeValue(
        Text(
            ToSubmittedByFilterDatePicker.SelectedDate,
            "[$-en-US]yyyy/mm/dd"
        ) & " 23:59"
    ) &&
    If(
        IsBlank(ClaimCodeFilterTextInput.Text),
        true,
        ClaimCodeFilterTextInput.Text in ClaimCode
    )
)

Set the OnChange property of the ApprovedByFilterComboBox to following:

If(
  !IsEmpty(ApprovedByFilterComboBox.SelectedItems),
  ClearCollect(
       LocalClaims,
       Filter('YourSPList', LineManagerApprover.DisplayName in ApprovedByFilterComboBox.SelectedItems)
   )
)

Set the OnChange property of the StatusFilterComboBox to following:

If(
  !IsEmpty(StatusFilterComboBox.SelectedItems),
  ClearCollect(
       LocalClaims,
       Filter('YourSPList', ClaimStatus.Value in StatusFilterComboBox.SelectedItems)
   )
)

Set the OnChange property of the SubmittedByFilterComboBox to following:

If(
  !IsEmpty(SubmittedByFilterComboBox.SelectedItems),
  ClearCollect(
       LocalClaims,
       Filter('YourSPList', SubmittedBy.DisplayName in SubmittedByFilterComboBox.SelectedItems)
   )
)

then check if the issue is solved.

 

Best regards,

Kris

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.

View solution in original post

toby-at-yell
Level: Powered On

Re: Limit to the number of expressions used when filtering a Collection

Thanks Kris, I'm marking this as the solution as it helped me actually find what was causing the problem.

The actual problem came from the SelectedItems property of the ComboBox control. This can either be null or empty. Need to do some more testing, but when it is first loaded and no items are selected, then IsBlank is true. If you then selected some items and then remove them IsBlank is false, but IsEmpty is true. To fix this I added an OR clause to test for both IsBlank or IsEmpty

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,542)