One field, two filters, how’s that possible?

Can you apply multiple filters to a single field? Yes, you can. I’m showcasing two different ways in this video. Check it out:

https://youtu.be/wGhwZkARdGc

In this video, Erik explores a common question in Business Central development: how can you apply two (or more) filters on the same field at the same time? He demonstrates two approaches — the ampersand (&) syntax for simpler cases, and filter groups for complex scenarios where both filter conditions must be satisfied simultaneously.

The Problem: Multiple Filter Criteria on One Field

Sometimes you need to find records where a field satisfies two different filter criteria at once — the intersection (union in set terms) of two filters. For example, you might have one filter that selects a range of accounts and another filter that selects a different range, and you need only the records that match both conditions.

Approach 1: The Ampersand (&) Syntax

Most Business Central users are familiar with the pipe (|) character in filters, which means “or.” Far fewer know about the ampersand (&), which means “and” — requiring that both parts of the filter be true.

Erik demonstrates this on the Chart of Accounts page:

  1. Set a filter on the account number: 11100..11400 — this is a simple range filter.
  2. Now combine two ranges with the ampersand: 11100..11400 & 11200..11700
  3. This returns only the records that fall within both ranges — the intersection.
  4. You can even chain a third: 11100..11400 & 11200..11700 & 11300..11450

This works well for range-based filters. However, it breaks down when you have complex “or” filters on both sides. For example, if one filter is 11200|11400|11700 and another is 11400|11500, trying to combine them with the ampersand doesn’t produce the expected result. The syntax simply can’t handle that level of complexity.

Approach 2: Filter Groups

For complex scenarios, Business Central provides filter groups. Behind the scenes, filters in Business Central are organized into numbered groups, each operating as an independent layer. A record must satisfy the filters in all active filter groups to appear in the result set.

Built-in Filter Groups

Business Central reserves certain filter group numbers for specific purposes:

  • Group 0 — Standard user filters (what you see in the normal filter pane)
  • Group 2 — Filters set via SetTableView, SourceTableView, or RunPageView
  • Group 4 — Data item links and subpage links
  • Group 6 — Security filters (cannot be manipulated from the UI)

You can see this in action when drilling down from a chart of accounts entry into ledger entries. The system filter on the G/L Account Number is set in a different filter group than the one visible to the user. That’s why you can still add your own filter on the same field — it’s applied in filter group 0 while the system filter lives in another group.

Building a Demo Page

Erik builds a simple list page on the Item table to demonstrate filter groups in AL code. Here’s the concept in action:

page 50100 "My Item List"
{
    PageType = List;
    SourceTable = Item;
    Editable = false;

    layout
    {
        area(Content)
        {
            repeater(Lines)
            {
                field("No."; Rec."No.") { }
                field(Description; Rec.Description) { }
            }
        }
    }

    trigger OnOpenPage()
    var
        OldGroup: Integer;
    begin
        // Save the current filter group
        OldGroup := Rec.FilterGroup;

        // Set a filter in filter group 10
        Rec.FilterGroup(10);
        Rec.SetFilter(Description, '@*desk*');

        // Set a different filter in filter group 11
        Rec.FilterGroup(11);
        Rec.SetFilter(Description, '@*fence*');

        // Restore the original filter group
        Rec.FilterGroup(OldGroup);
    end;
}

With this setup, only items whose description contains both “desk” and “fence” will appear. An item named just “Desk” won’t show, nor will one named just “Athens Fence” — only items matching both filter groups qualify.

Combining Complex Filters

This is where filter groups truly shine. You can apply complex filters with pipes and ranges in each group independently:

trigger OnOpenPage()
var
    OldGroup: Integer;
begin
    OldGroup := Rec.FilterGroup;

    // First complex filter
    Rec.FilterGroup(10);
    Rec.SetFilter("No.", '1001|1002|1003');

    // Second complex filter
    Rec.FilterGroup(11);
    Rec.SetFilter("No.", '1001|1003|1005');

    // Only items with No. matching BOTH filters will show
    // Result: 1001 and 1003 (the intersection)

    Rec.FilterGroup(OldGroup);
end;

In this example, only items 1001 and 1003 would appear since they’re the only values present in both filter sets.

How Many Filter Groups Can You Use?

Erik experimented with higher filter group numbers and confirmed that at least 200+ groups work. He wasn’t able to pin down the exact maximum, but even with a limit around 200, that’s far more than you’d ever realistically need.

Important: Filter Group Etiquette

When working with filter groups, always follow this pattern:

  1. Save the current filter group before switching
  2. Do your work in whatever custom filter groups you need
  3. Restore the original filter group when you’re done
var
    OldGroup: Integer;
begin
    OldGroup := Rec.FilterGroup;
    
    // ... your filter group manipulations ...
    
    Rec.FilterGroup(OldGroup);
end;

This is especially critical when working with event subscribers, where you receive records as VAR parameters. If you change the filter group and don’t restore it, you could corrupt the filtering state for the calling code, leading to subtle and hard-to-diagnose bugs.

Source Code Reference

The source project Erik used is a simple AL extension. Here’s the page extension from the project that demonstrates basic filtering:

namespace DefaultPublisher.AtFiltering;

using Microsoft.Sales.Customer;

pageextension 50100 CustomerListExt extends "Customer List"
{
    trigger OnOpenPage();
    begin
        Rec.SetRange(Name, 'test|Test|TEST');
    end;
}

Summary

When you need to apply multiple filters on the same field in Business Central:

  • Use the ampersand (&) syntax for simple cases where you’re combining ranges — e.g., 11100..11400 & 11200..11700. It’s easy and works directly in the UI or in code.
  • Use filter groups for complex scenarios where each filter involves pipes, multiple values, or ranges that can’t be cleanly combined with &. Filter groups let you layer independent filter conditions, and a record must pass all of them to appear.
  • Always save and restore the filter group to avoid unintended side effects, especially in event subscribers.