> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Filter Assignments for Sample Size Calculations

> Learn how to filter past assignments on flags to improve sample size calculations.

export const HowToSchema = ({name, description, steps = []}) => {
  const schema = {
    "@context": "https://schema.org",
    "@type": "HowTo",
    name,
    description
  };
  if (steps.length > 0) {
    schema.step = steps.map((s, i) => ({
      "@type": "HowToStep",
      position: i + 1,
      name: typeof s === "string" ? s : s.name,
      text: typeof s === "string" ? s : s.text || s.name
    }));
  }
  return <script type="application/ld+json" dangerouslySetInnerHTML={{
    __html: JSON.stringify(schema)
  }} />;
};

<HowToSchema
  name="Filter Assignments for Sample Size Calculations"
  description="Learn how to filter past assignments on flags to improve sample size calculations."
  steps={[
"Go to Admin > Assignment tables",
"Select Edit query",
{
  name: "Adjust the SQL query to include a flag column",
  text: "Add a column called flag to your SQL query. The name can be in any case.",
},
"Select Run query",
{
  name: "Select the flag column",
  text: "In the Configure table section, select the column from the Flag column dropdown.",
},
"Select Save",
{
  name: "Select your experiment",
  text: "Select the experiment you want to run the sample size calculation for.",
},
{
  name: "Open the sample size calculation widget",
  text: "Click the icon in the Required sample size section to open the sample size calculation widget.",
},
{
  name: "Edit the exposure source",
  text: "Click the edit icon in the Exposure source section to edit the exposure source.",
},
{
  name: "Select flags to filter on",
  text: "Select Assignments as the exposure source and add the flags you want to filter on.",
},
]}
/>

When calculating [required sample size](../experiments/sample-size-calculator), you can filter past assignments on flags to include only users similar to those in your upcoming experiment.

## Why Filter Assignments

Users assigned by a flag that assigns all users behave differently from a flag that only assigns highly engaged users. This means the mean and variance of metrics differ for the two cohorts, and so do the required sample sizes. By filtering assignments in the exposure source on relevant flags, you ensure the exposure source is as similar as possible to your upcoming experiment.

## Enable Assignment Filtering

<Steps>
  <Step title="Go to Admin > Assignment tables" />

  <Step title="Select Edit query" />

  <Step title="Adjust the SQL query to include a flag column">
    Add a column called `flag` to your SQL query. The name can be in any case.
  </Step>

  <Step title="Select Run query" />

  <Step title="Select the flag column">
    In the **Configure table** section, select the column from the **Flag column** dropdown.
  </Step>

  <Step title="Select Save" />
</Steps>

## Filter Past Assignments on Flags

<Steps>
  <Step title="Select your experiment">
    Select the experiment you want to run the sample size calculation for.
  </Step>

  <Step title="Open the sample size calculation widget">
    Click the icon in the **Required sample size** section to open the sample size calculation widget.
  </Step>

  <Step title="Edit the exposure source">
    Click the edit icon in the Exposure source section to edit the exposure source.
  </Step>

  <Step title="Select flags to filter on">
    Select **Assignments** as the exposure source and add the flags you want to filter on.
  </Step>
</Steps>

## Related Resources

<CardGroup cols={2}>
  <Card title="Calculate Sample Size" href="/docs/how-to-guides/calculate-sample-size">
    Run sample size calculations
  </Card>

  <Card title="Sample Size Calculator Reference" href="/docs/experiments/sample-size-calculator">
    Deep dive into sample size calculations
  </Card>

  <Card title="Assignment Tables" href="/docs/metrics/assignment-tables">
    Configure assignment data sources
  </Card>

  <Card title="Power Analysis" href="/docs/experiments/design/power">
    Understand statistical power
  </Card>
</CardGroup>
