### Answer

Using the PREVIOUS_VALUE() function we can count the number of consecutive days in a streak in one calculation that starts with the first value in the data and reads down (e.g. the first day to the last day). Then a second calculation can keep track of the largest non-zero value by reading the values from last value to first (e.g. the last day to the first day).

The attached example workbook uses the sample data set Superstore to demonstrate the following directions:

1. Create a calculated field with a name like "Running count of consecutive days of neg profit" with a calculation similar to the following:

`IF SUM( [Profit] ) < 0`

THEN PREVIOUS_VALUE(0) + 1

ELSE 0

END

2. Create a calculated field with a name like "Running Count Groups" with a calculation similar to the following:

`IF [Running count of consecutive days of neg profit] = 0`

THEN 0

ELSE MAX(PREVIOUS_VALUE(0), [Running count of consecutive days of neg profit])

3. Drag [Running Count Groups] to the **Measure Values **card

4. Right-click [Running Count Groups] on the **Measure Values **card and select** Edit Table Calculation…**

5. In the **Table Calculation **dialog, do the following and close the dialog:
- For
**Nested Calculations**, select **Running count **of consecutive days of neg profit - For
**Compute Using**, select **Table (down)** - For
**Nested Calculations**, select **Running Count Groups** - For
**Compute Using**, select **Table (down)** - For
**Compute Using**, select **Specific Dimensi**ons - For
**Sort order **select **Custom, Order Date, Minimum, Descending**