---
title: Assette Get Valid Periods Data Block
description: "*The Assette Get Valid Periods (ast_fn_GetValidPeriods) Data Block is an Open Source Data Block and may be copied or edited.* The Assette Get Valid Periods (*ast_fn_GetValidPeriods*) Data Block processes a list of periods (e.g., `MTD`, `QTD`, `YTD`, etc.) based on…"
url: "https://learn.assette.com/docs/assette-get-valid-periods-data-block/"
updated: "2025-06-09"
category: Developers / Data Blocks / Data Blocks by Category / Transform Data Blocks
---

# Assette Get Valid Periods Data Block

*The Assette Get Valid Periods (ast_fn_GetValidPeriods) Data Block is an Open Source Data Block and may be copied or edited.*

The Assette Get Valid Periods (*ast_fn_GetValidPeriods*) Data Block processes a list of periods (e.g., `MTD`, `QTD`, `YTD`, etc.) based on parameters such as the reference date (`AsofDate`), fiscal year-end, and inception date. It retrieves the `begin_date` and `end_date` for each period and allows for optional filtering of non-applicable and duplicate periods. The Assette Get Valid Periods (*ast_fn_GetValidPeriods*) Data Block then organizes and returns the calculated date ranges in a structured format. This Data Block is open-source and may be edited as desired.

### Input Parameters:

- **AsofDate**: The reference date for calculating periods.
- **PeriodList**: A comma-separated list of period codes (e.g., `MTD`, `QTD`, `YTD`, etc.) to calculate.
- **SuppressNotApplicablePeriods**: If `"yes"`, excludes periods that begin before the `InceptionDate`.
- **SuppressDuplicatePeriods**: If `"yes"`, removes duplicate periods based on `begin_date` and `end_date`, prioritizing certain period codes.
- **FiscalYearEnd**: The fiscal year-end date, used for fiscal period calculations.
- **InceptionDate**: The date from which the relevant periods start.
- **DatePattern**: The format of dates in the input and output (e.g., `"%Y-%m-%dT%H:%M:%S"`).

The Assette Get Valid Periods (*ast_fn_GetValidPeriods*) Data Block reads the `begin_date` and `end_date` for each period by calling `ast_fn_GetBeginEndDates`, passing the period code, `AsofDate`, `InceptionDate`, and `FiscalYearEnd`.

- The retrieved dates are added to a Pandas DataFrame (`period_frame`) with columns `period`, `begin_date`, and `end_date`.
- **Suppress Not Applicable Periods**: If `SuppressNotApplicablePeriods` is `"yes"`, the Data Block filters out periods where the `begin_date` is before the `InceptionDate`.
- **Suppress Duplicate Periods**:
  - If `SuppressDuplicatePeriods` is `"yes"`, a ranking system is applied to prioritize certain periods (e.g., `MTD`, `QTD`, `YTD`, `12MT`).
  - Duplicate periods (same `begin_date` and `end_date`) are removed based on the ranking. For example, `MTD` might take precedence over `QTD` if they share the same date range.

## General Info

*The following table shows the default fields of the Data Block*.

| Field | Value |
| --- | --- |
| Name | ast_fn_GetValidPeriods |
| Block Category | Transform |
| Block Type | Python |
| Data Category | None |
| Output Type | Data Table |
| Editable | True |

## Dependencies

*The following table shows the default dependencies of the Data Block*.

| Data Block | Description |
| --- | --- |
| PythonEnvForDateCalculation | [Link] |
| ast_fn_GetBeginEndDates | [Link] |

## Example Definition

```
"""
params:{
    "AsofDate": "TRADEDATE",
    "PeriodList": "MTD,QTD",
    "SuppressNotApplicablePeriods":"yes" or "no",
    "SuppressDuplicatePeriods":"yes" or "no",
    "FiscalYearEnd": "04-30",
    "InceptionDate": "2017-12-07",
    "DatePattern": "%Y-%m-%dT%H:%M:%S"
    }

test param values:{
    "AsofDate": "2023-04-30",
    "InceptionDate": "2017-12-07",
    "FiscalYearEnd": "04-30",
    "SuppressNotApplicablePeriods": "yes",
    "SuppressDuplicatePeriods": "yes",
    "PeriodList": "MTD,QTD,YTD,12MT,3YA,5YA,5YC,7YA,10YA,ITDA",
    "DatePattern": "%Y-%m-%dT%H:%M:%S"
}

response = [
        {
            "period": "MTD",
            "begin_date": "2023-03-31 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "YTD",
            "begin_date": "2022-12-31 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        }
    ]
"""
suppress_not_applicable = params["SuppressNotApplicablePeriods"]
suppress_duplicate_periods = params["SuppressDuplicatePeriods"]
period_list = params["PeriodList"].split(",")
date_pattern = ""
if "DatePattern" in params.keys():
    date_pattern = params["DatePattern"].strip()

if len(date_pattern) == 0:
    date_pattern = '%Y-%m-%d'

period_func_params = {"AsofDate": params["AsofDate"], "PeriodCode": "", "InceptionDate": params["InceptionDate"], "FiscalYearEnd": params["FiscalYearEnd"],"DatePattern": date_pattern}
inception_date = datetime.datetime.strptime(params["InceptionDate"],'%Y-%m-%d')
period_frame = pd.DataFrame(columns=["period", "begin_date", "end_date"])
period_index = 0

for period_code in period_list:
    period_func_params["PeriodCode"] = period_code
    period_begin_end_dates = read("ast_fn_GetBeginEndDates", period_func_params)["data"]
    begin_date = datetime.datetime.strptime(period_begin_end_dates[0]["begin_date"], '%Y-%m-%d')
    end_date = datetime.datetime.strptime(period_begin_end_dates[0]["end_date"], '%Y-%m-%d')
    period_frame.at[period_index, "period"] = period_code
    period_frame.at[period_index, "begin_date"] = begin_date
    period_frame.at[period_index, "end_date"] = end_date
    period_index += 1

if suppress_not_applicable == "yes":
    period_frame = period_frame.loc[period_frame['begin_date'] >= inception_date]

if suppress_duplicate_periods == "yes":
    # period_frame = period_frame.drop_duplicates(["begin_date","end_date"])
    rank_mapping = {"MTD": 1, "QTD": 2, "YTD": 3, "12MT": 4}
    period_frame["RANK"] = period_frame["period"].map(rank_mapping)
    period_frame["RANK"].fillna("", inplace=True)

    selected_periods = ["QTD", "MTD", "YTD", "12MT"]
    filtered_period_frame = period_frame[period_frame["period"].isin(selected_periods)]
    period_frame = period_frame[~period_frame["period"].isin(selected_periods)]
    filtered_period_frame.sort_values(by=["RANK", "begin_date"], ascending=[True, True], inplace=True)
    filtered_period_frame.drop_duplicates(subset=["begin_date", "end_date"], keep="first", inplace=True)
    period_frame = pd.concat([filtered_period_frame, period_frame], ignore_index=True)
    period_frame = period_frame.drop(columns=["RANK"])

period_frame['begin_date'] = period_frame['begin_date'].astype(str)
period_frame['end_date'] = period_frame['end_date'].astype(str)
# print(period_frame)
output_list = period_frame.to_dict(orient='records')
response['data'] = output_list
# response['data'] = period_func_params
```

## Example Request

*The following code shows an example request using the default values of the Data Block*.

```
{
    "AsofDate": "2023-04-30",
    "InceptionDate": "2017-12-07",
    "FiscalYearEnd": "04-30",
    "SuppressNotApplicablePeriods": "yes",
    "SuppressDuplicatePeriods": "yes",
    "PeriodList": "MTD,QTD,YTD,12MT,3YA,5YA,5YC,7YA,10YA,ITDA",
    "DatePattern": "%Y-%m-%d"
}
```

## Example Response

*The following code shows an example response using the default values of the Data Block. The default data source is the Assette Snowflake Demo Instance. The response may be shortened for brevity*.

```
{
    "data": [
        {
            "period": "MTD",
            "begin_date": "2023-03-31 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "YTD",
            "begin_date": "2022-12-31 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "12MT",
            "begin_date": "2022-04-30 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "3YA",
            "begin_date": "2020-04-30 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "5YA",
            "begin_date": "2018-04-30 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "5YC",
            "begin_date": "2018-04-30 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        },
        {
            "period": "ITDA",
            "begin_date": "2017-12-07 00:00:00",
            "end_date": "2023-04-30 00:00:00"
        }
    ],
    "errors": [],
    "success": true,
    "logs": []
}
```
