# ExpectTableRowCountToBeBetween seems to ignore row\_condition

**URL:** <https://discourse.greatexpectations.io/t/expecttablerowcounttobebetween-seems-to-ignore-row-condition/2275>\
**Category:** GX Core Support\
**Tags:** help-wanted\
**Created:** [August 5, 2025, 12:57pm UTC](https://discourse.greatexpectations.io/t/expecttablerowcounttobebetween-seems-to-ignore-row-condition/2275 "2025-08-05T12:57:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [August 5, 2025, 12:57pm UTC](https://discourse.greatexpectations.io/t/expecttablerowcounttobebetween-seems-to-ignore-row-condition/2275/1 "2025-08-05T12:57:58Z")

</div>

In GX 1.5.7, my `ExpectTableRowCountToBeBetween` expectations seem to be ignoring their `row_condition`s. Inspecting the results, the `observed_value` in each case is the entire table row count, not just the rows satisfying the condition.

Is this expected? `expect_table_row_count_to_be_between` is not included in the [list of limitations](https://docs.greatexpectations.io/docs/core/customize_expectations/expectation_conditions/?condition_parser=spark#scope-and-limitations) for using row conditions.

I have tried setting the `condition_parser` to both `"spark"` (which worked perfectly in GX 0.18) and to `"great_expectations"` (as recommended by the newer documentation), but in both cases the condition is not applied.

Here are some example expectations:

```json
    {
      "type": "expect_table_row_count_to_be_between",
      "kwargs": {
        "min_value": 99,
        "max_value": 101,
        "row_condition": "col(\"Cohort\") == \"MyCohort\"",
        "condition_parser": "great_expectations"
      },
      "meta": {
        "notes": {
          "format": "markdown",
          "content": [
            "Expect row count for **Cohort == MyCohort** to be within **1%** of the row count seen in the most recent successful validation run"
          ]
        }
      },
    },
    {
      "type": "expect_table_row_count_to_be_between",
      "kwargs": {
        "min_value": 198,
        "max_value": 202,
        "row_condition": "col(\"Cohort\") == \"MyCohort2\"",
        "condition_parser": "great_expectations"
      },
      "meta": {
        "notes": {
          "format": "markdown",
          "content": [
            "Expect row count for **Cohort == MyCohort2** to be within **1%** of the row count seen in the most recent successful validation run"
          ]
        }
      },
    },

```

If my data file has 100 rows for MyCohort and 200 for MyCohort2, both expectations fail with an observed value of 300.

---

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [August 28, 2025, 1:36pm UTC](https://discourse.greatexpectations.io/t/expecttablerowcounttobebetween-seems-to-ignore-row-condition/2275/2 "2025-08-28T13:36:02Z")

</div>

I have come up with a workaround, which I am sharing here in case anyone else face the same issue.

`ExpectColumnSumToBeBetween` works with a `row_condition`. So, if I add a column of 1s to my data frame before passing it to the checkpoint…

```python
from pyspark.sql.functions import lit
spark_data_frame = spark_data_frame.withColumn("RowCount", lit(1))

```

… then, instead of using `ExpectTableRowCountToBeBetween` I can use `ExpectColumnSumToBeBetween`, looking at the `RowCount` column and with whatever `min_value` and `max_value` I expect for the row count.

```json
    {
      "type": "expect_column_sum_to_be_between",
      "kwargs": {
        "column": "RowCount",
        "min_value": 99,
        "max_value": 101,
        "row_condition": "col(\"Cohort\") == \"MyCohort\"",
        "condition_parser": "great_expectations"
      },
      "meta": {
        "notes": {
          "format": "markdown",
          "content": [
            "Expect row count for **Cohort == MyCohort** to be within **1%** of the row count seen in the most recent successful validation run"
          ]
        }
      },
    },
    {
      "type": "expect_column_sum_to_be_between",
      "kwargs": {
        "column": "RowCount",
        "min_value": 198,
        "max_value": 202,
        "row_condition": "col(\"Cohort\") == \"MyCohort2\"",
        "condition_parser": "great_expectations"
      },
      "meta": {
        "notes": {
          "format": "markdown",
          "content": [
            "Expect row count for **Cohort == MyCohort2** to be within **1%** of the row count seen in the most recent successful validation run"
          ]
        }
      },
    },

```

---

<div class="post-metadata">

**Author:** ![Nathan](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/nathan/32/389_2.png) [@Nathan](https://discourse.greatexpectations.io/u/Nathan)\
**Post date:** [October 22, 2025, 6:01pm UTC](https://discourse.greatexpectations.io/t/expecttablerowcounttobebetween-seems-to-ignore-row-condition/2275/3 "2025-10-22T18:01:11Z")

</div>

Hi @mike_f50, we fixed the bug with ExpectTableRowCountToBeBetween [here](https://github.com/great-expectations/great_expectations/pull/11467/files). The fix should go out with this week’s release.

---

<div class="post-metadata">

**Author:** ![mike\_f50](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.greatexpectations.io/mike_f50/32/169_2.png) [@mike\_f50](https://discourse.greatexpectations.io/u/mike_f50)\
**Post date:** [October 31, 2025, 11:59am UTC](https://discourse.greatexpectations.io/t/expecttablerowcounttobebetween-seems-to-ignore-row-condition/2275/4 "2025-10-31T11:59:40Z")

</div>

Nice! I’ll give it a try.
