Advanced Set Analysis - Alternate States

Alternate States
in Qlik Sense

The most underused Qlik Sense feature: compare two independent selection contexts simultaneously in the same chart, without duplicating objects or hardcoding filters.

~18 min read Qlik Sense / QlikView Expert Level
Scroll
Section 01 - Core Concept

What is an Alternate State?

By default, a Qlik app has one selection state: the user clicks "Southeast" and every object reflects that selection. Alternate States break this constraint, enabling different objects to operate in independent, simultaneous selection contexts.

The Problem It Solves

Consider this scenario: an analyst needs to compare the performance of two products with different filters applied to each, without creating a second app, without opening two tabs, without hardcoded Set Analysis values. Alternate States is Qlik's native answer to this problem.

Default State
{$}
Region: South
Year: 2024
VS
Alternate State
{Scenario_B}
Region: North
Year: 2023

Both states coexist in the same app at the same time. A single chart can display both values side by side. Users make selections in each state completely independently.

Set Analysis Syntax with States

// Default state - same as {$}
Sum({$} Revenue)

// Alternate state by name
Sum({Scenario_B} Revenue)

// Alternate state + additional modifier
Sum({Scenario_B<Status={'Active'}>} Revenue)

// Difference between the two states
Sum({$} Revenue) - Sum({Scenario_B} Revenue)

// YoY % comparison between states
Num(
    (Sum({$} Revenue) / Sum({Scenario_B} Revenue)) - 1,
    '+#,##0.0%;-#,##0.0%;0.0%'
)
πŸ’‘
Full syntax: {StateName<Field={'Value'}>}. The state name replaces the default identifier ($ or 1). The modifier <> is optional - without it, the expression uses exactly the selections active in that state at runtime.

State vs. Hardcoded Set Analysis

Set with {1} - Static
// Always ignores ALL selections
// Not interactive - never changes
Sum({1<Region={'South'}>} Revenue)

// Value is fixed regardless of
// what the user selects
Alternate State - Dynamic
// Uses selections of state Scenario_B
// The user can change those selections!
Sum({Scenario_B} Revenue)

// Value updates as user interacts
// with objects assigned to that state
Section 02 - Use Cases

Why Use Alternate States?

Alternate States are not a feature for simple scenarios. They exist to solve comparative analysis problems that would otherwise require complex, fragile workarounds.

πŸ“Š

Period Comparison

User selects January in State A and February in State B. A single bar chart shows both months side by side with the same dimensions, zero hardcoding.

πŸ—ΊοΈ

Region Benchmarking

Live benchmark between two regions chosen by the analyst. South vs North, Branch A vs Branch B - the choice belongs to the user, not the developer.

πŸ”¬

What-If Analysis

Current state vs simulated scenario. The default state reflects reality; the alternate state reflects a hypothesis with different filters, budget, or product mix.

πŸ›’

Basket Analysis

Customers who bought Product A (State A) vs customers who bought Product B (State B). Which basket has a higher average ticket? More repeat purchases?

πŸ’Ή

Currency / Economic Scenario

Same data with two different exchange rates. The CFO wants to see results in USD and BRL simultaneously with the same product and region filters.

🎯

Actual vs Target

Actual performance (default state) vs adjusted target (alternate state with modifiers). The variance is calculated directly in the expression.

When NOT to Use Alternate States

Section 03 - Setup

Creating and Configuring States

States are created in the Qlik Sense interface and then referenced in any Set Analysis expression by the exact name you defined.

Step 1 - Create the State in the Interface

1

Edit Sheet

Click "Edit sheet" in the top right corner. In the sheet properties panel (not the object panel), find the Alternate States section.

2

Add State

Click "Add state". Define a name without spaces or special characters - this is the name you will use in Set Analysis. Ex: Scenario_B, Period_2.

3

Assign to Object

Select the object (filter pane, chart, KPI). In the object properties panel, find State and select the created state. That object now operates in the new state.

⚠️
Naming convention: Use descriptive, consistent names. Scenario_A and Scenario_B are generic but functional. Selected_Period and Benchmark_Region are better for production dashboards. Never use spaces or special characters - the name must be valid as an expression identifier.

Step 2 - Create Filter Panes for Each State

Filter A

Filter Pane - Default State ($)

Displays dimensions (Region, Product, Year). Object is assigned to the default state. Selections here affect all objects using {$}.

Filter B

Filter Pane - Scenario_B

Displays the same dimensions. Object is assigned to state Scenario_B. Selections here only affect objects that reference this state in their expressions.

Step 3 - Reference in Set Analysis

// The comparison chart stays in the default state
// It simply has two measures:

// Measure 1 - uses default state selections
Sum({$} Revenue)
// Label: "Revenue - Selection A"

// Measure 2 - uses Scenario_B state selections
Sum({Scenario_B} Revenue)
// Label: "Revenue - Selection B"

// Measure 3 - absolute difference between both states
Sum({$} Revenue) - Sum({Scenario_B} Revenue)
// Label: "Variance A vs B"

// Measure 4 - percentage variation
Num(
    (Sum({$} Revenue) / Sum({Scenario_B} Revenue)) - 1,
    '+#,##0.0%;-#,##0.0%;0.0%'
)
Section 04 - Advanced Patterns

Production Patterns with Alternate States

These battle-tested patterns combine Alternate States with the techniques from the previous articles: modifiers, P(), dollar-sign expansion, and dynamic periods.

Pattern 1 - Dynamic Regional Benchmark

// Setup: Two Region filter panes (State $ and State Region_B)
// User chooses any region in each filter independently

// Dynamic label showing which region is active per state
'Selected: ' & Concat({$} DISTINCT Region, ', ')
'Benchmark: ' & Concat({Region_B} DISTINCT Region, ', ')

// Revenue comparison
Sum({$} Revenue)           // Region A
Sum({Region_B} Revenue)  // Region B

// Variance
Num(
    Sum({$} Revenue) / Sum({Region_B} Revenue) - 1,
    '+#,##0.0%;-#,##0.0%;0.0%'
)

Pattern 2 - Cohort Analysis with State + P()

// Default state: customers who bought Product A
// State Cohort_B: customers who bought Product B
// Question: what is the cross-revenue between both groups?

// Customers exclusive to State A (bought A but not B)
Count(
    {$<CustomerID =
        P({$} CustomerID)
        -
        P({Cohort_B} CustomerID)
    >}
    DISTINCT CustomerID
)

// Customers in BOTH states (bought A and B)
Count(
    {$<CustomerID =
        P({$} CustomerID)
        *
        P({Cohort_B} CustomerID)
    >}
    DISTINCT CustomerID
)

// Revenue from overlapping customers
Sum(
    {$<CustomerID =
        P({$} CustomerID) * P({Cohort_B} CustomerID)
    >}
    Revenue
)

Pattern 3 - State + Dynamic Period

// State A: South Region, user's default period
// State Period_2: North Region, different period

// YTD for default selection
Sum({$<Year={$(=Max({1}Year))},
     Month={"<=$(=Month(Today()))"}>} Revenue)

// YTD for alternate state - same period logic, different selections
Sum({Period_2<Year={$(=Max({1}Year))},
              Month={"<=$(=Month(Today()))"}>} Revenue)

Pattern 4 - What-If Scenario

// Default state: actual performance
// State WhatIf: simulated scenario with different filters

// Actual
Sum({$} Revenue)

// Simulated: WhatIf state + Premium segment only
Sum({WhatIf<Segment={'Premium'}>} Revenue)

// Impact (absolute)
Sum({$} Revenue) - Sum({WhatIf} Revenue)

// Impact (percentage, signed)
Num(
    (Sum({$} Revenue) - Sum({WhatIf} Revenue)) /
    Abs(Sum({WhatIf} Revenue)),
    '+#,##0.0%;-#,##0.0%;0.0%'
)
Section 05 - Reference

Quick Reference and Common Mistakes

Full Syntax Reference

ExpressionMeaningWhen to Use
Sum({$} Revenue)Default state (current selections)Base reference measure
Sum({1} Revenue)All records, ignores selectionsFixed absolute total
Sum({Scenario_B} Revenue)Scenario_B state selectionsA vs B comparison
Sum({Scenario_B<Status={'Active'}>} Revenue)State B + additional modifierState B with extra condition
Count({$} DISTINCT ID) - Count({Scenario_B} DISTINCT ID)Count difference between statesCustomer base growth/decline
P({$} CustomerID) * P({Scenario_B} CustomerID)Customer intersection between statesBasket / cohort analysis
Sum(TOTAL {Scenario_B} Revenue)State B total, ignores chart dimensionsCross-state share %

Common Mistakes and Fixes

βœ—

Wrong State Name Case

The name in Set Analysis must be identical to the name created in the interface, including upper/lowercase and underscores. {scenario_b} is different from {Scenario_B}.

βœ—

Object Not Assigned to State

Creating the state is not enough. Each object (filter pane, button) must be explicitly assigned to the correct state via the properties panel. A filter pane in the default state does not feed an alternate state.

βœ—

Chart Responding to Wrong State

The comparison chart must be in the default state ($) to show both measures. If the chart itself is assigned to a specific state, it only reflects that state's selections.

βœ—

Confusing State with Modifier

{Scenario_B<Field={'Val'}>} uses State B selections AND adds the modifier. {$<Field={'Val'}>} uses default state with modifier. These are different contexts.

Production Checklist