Tableau Funtion: WINDOW_COUNT( )

Tableau Function: WINDOW_COUNT( )

Category: Table Calculation Functions

What Is the Function?

Purpose of the Function

The WINDOW_COUNT() function in Tableau is a table calculation that returns the count of non-null values within a defined window of rows in a partition. Unlike RUNNING_COUNT(), which accumulates progressively, WINDOW_COUNT() allows you to specify a custom range (window) over which the count is calculated.

In simple terms, WINDOW_COUNT() answers:
“How many non-null values exist within this specific range?”

Type of Calculations

  • Table calculations

  • Window-based aggregations

  • Count-based analytics

  • Order-dependent calculations

WINDOW_COUNT() is evaluated after aggregation and depends on partitioning, sorting, and compute direction.

Practical Use Cases

  • Counting records within rolling time windows

  • Calculating moving averages (when combined with WINDOW_SUM())

  • Measuring activity within recent periods (e.g., last 7 days)

  • Supporting rate and density calculations

  • Identifying window-based thresholds or milestones


WINDOW_COUNT(expression, [start, end])

ParameterTypeDescription
expressionAggregate / table calculationThe numeric or field expression to count within the window. Only non-null values are counted.
start (optional)IntegerStarting row offset relative to the current row.
end (optional)IntegerEnding row offset relative to the current row.

How It Works?

Mathematical / Logical Principle

WINDOW_COUNT() calculates:

WINDOW_COUNT = COUNT(non-null values in defined window)

The window is defined using offsets relative to the current row.

Return Value

  • Data Type: Integer

  • Meaning:

    • Returns the count of non-null values within the defined window

    • Can vary by row depending on window boundaries

When Should We Use It?

Use WINDOW_COUNT() when you need to:

  • Count records within a sliding or fixed window

  • Support rolling averages or ratios

  • Analyze short-term trends

  • Build window-based statistical calculations

  • Normalize values within a range

Basic Usage

Count values across full partition


WINDOW_COUNT(SUM([Sales]))

Returns total non-null rows in partition

Column Usage

3-period rolling count


WINDOW_COUNT(SUM([Sales]), -2, 0)

Counts values for current row and previous two rows

Centered rolling count


WINDOW_COUNT(SUM([Sales]), -1, 1)

Counts values for previous, current, and next rows

Advanced Usage

Rolling average using window functions


WINDOW_SUM(SUM([Sales]), -2, 0)
/
WINDOW_COUNT(SUM([Sales]), -2, 0)

Calculates 3-period moving average manually

Conditional window count


WINDOW_COUNT(
IF SUM([Profit]) > 0 THEN 1 END,
-3,
0
)

Counts only rows meeting a condition

Tips and Tricks

  • Only non-null values are counted

  • Always verify Compute Using and partition settings

  • Use with WINDOW_SUM() for custom averages

  • Sensitive to sorting

  • Window exceeding partition boundaries is auto-adjusted

Related Functions

Functions commonly used alongside or as alternatives to WINDOW_COUNT():

  • RUNNING_COUNT()

  • COUNT()

  • WINDOW_SUM()

  • WINDOW_AVG()

  • SIZE()

  • INDEX()

We’ve got plenty of resources to help you master Tableau functions. For more details, check out the official Tableau documentation. Or, if you’re ready for more practice, let’s dive into related functions and build your Tableau skills further!

If you’re ready to harness the full power of Tableau and elevate your data analytics capabilities, our expert Tableau consulting services are here to guide you. Whether you need support with building advanced calculated fields, creating dynamic visual dashboards, or optimizing your data sources for peak performance, our team of experienced Tableau consultants delivers customized solutions designed for your business needs. Visit our Tableau Consulting page to discover how we can help your organization turn data into impactful, insight-driven decisions.

1. What does WINDOW_COUNT() do in Tableau?

It counts non-null values within a defined window of rows.

2. How is WINDOW_COUNT() different from RUNNING_COUNT()?

WINDOW_COUNT() counts values within a specified range, while RUNNING_COUNT() accumulates progressively.

3. Is WINDOW_COUNT() affected by sorting?

Yes, sorting determines the order of rows in the window.

4. Does WINDOW_COUNT() include NULL values? No, only non-null values are counted.

No, only non-null values are counted.

5. Can WINDOW_COUNT() be used for rolling analysis?

Yes, by defining start and end offsets.