• Home
  • Visit Our Website
  • Home
  • Visit Our Website
Visit Our Website

Users

167
  • Getting Started
    • How to Log into Assette
    • The Assette Home Page
    • The Assette Navigation Bar
    • Glossary
  • Authoring Center
    • Smart Docs
      • Smart Docs
      • How to Create a Smart Doc
      • Copying and Restoring from Version History
      • Tracking Changes with Life Events
      • Smart Docs X-Ray View
      • Smart Doc Troubleshooting
      • Troubleshooting
        • Troubleshooting Smart Docs
    • Smart Pages
      • Creating & Editing Smart Pages
      • Smart Pages
      • How to Unlock a Smart Page
      • Deleting Smart Pages
      • Tracking Changes with Life Events
      • How to Insert Blank Columns and Rows
      • Changing a Smart Page’s Size
      • Supported PowerPoint Charts
      • Copying and Restoring from Version History
      • Smart Page X-Ray View
      • Smart Page Content Classifications
      • Compliance Tags
      • Assette Editors
        • PowerPoint Editor
          • How to Add New Series to a Chart
          • How to Insert Images Using the Assette Ribbon
          • Assette Ribbon
            • The “Un-Fabricate” Button
          • Troubleshooting
            • Resolving “Failed to Open” Errors in the Assette PPTX Editor
            • Installing the Assette PowerPoint Editor
            • How to Check Your Microsoft PowerPoint Version
          • Advanced Settings
            • Advanced Settings Overview
            • General Tab
            • Margin Tab
            • Zigzag Tab
    • Disclosures
      • Managing Disclosure Fragment Categories
      • Creating or Editing a Disclosure Fragment
      • Disclosures versus Footnotes
      • Disclosures
    • Fixed Content
      • Fixed Content
    • Data Docs
      • Data Docs
    • Smart Shells
      • How to Preview Smart Shells
      • Coupled Shells
      • Smart Shells
      • Tracking Changes with Life Events
      • Copying and Restoring from Version History
      • Creating Smart Shells Using the Smart Shell Library
      • Editing Smart Shells Using the Smart Shell Library
      • Creating Smart Shells via Assette’s PowerPoint Editor
      • How to Refresh Smart Shells
      • Deleting Smart Shells
      • Renaming Smart Shells
      • Smart Shells X-Ray View
      • Smart Shell Content Classifications
      • Performance History Chart
      • Smart Shells Frequently Asked Questions (FAQ)
      • Creating an “As of Date” Smart Shell
    • Brand Themes
      • Assette Dynamic Brand Theme Setup
      • Brand Themes
      • Managing Multiple Themes Within a Single Brand Theme
      • Creating a Brand Theme
      • Shell Styling
      • Dynamic Brand Themes
      • Master Slide Layouts for Dynamic Brand Themes
      • Changing a Smart Page’s Size
    • Email Templates
      • Using Variables in Assette Email Templates
      • Email Templates
    • Additional Features
      • Using Quick View in Assette
      • Automatic Extension Correction
      • X-Ray View Overview
      • The Generation Screen
    • Authoring FAQs
      • Understanding the Difference Between My Workspace and Workrooms
      • What’s the Difference between Footnotes & Coupled Shells?
  • Content Hub
    • Library
      • Saved Trays in the Assette Library
      • Content Library
      • Content Generation and Sharing with Content Library
    • My Workspace
      • Copying Content to My Workspace
      • My Workspace
    • RFPs & DDQs
      • Editing an RFP Answer
      • Uploading an RFP to the Assette
      • RFPs & DDQs
    • Workrooms
      • How to Edit Content in a Workroom
      • Copying Content to a Workroom
      • Workroom
    • Assette Viewer
      • Disabling or Removing the Assette Outlook Add-in
      • Assette Viewer Overview
      • Assette Viewer Basics
    • Content Center
      • How to Add a New Organization to the Organization Master
      • Content Plan Data Model
      • Content Plans
      • Content Types
      • Using Advanced Search in the Content Library
  • Data Engine
    • Input Center
      • Input Center Overview
      • Data Files Overview
      • Recipients
      • External Content Overview
    • Data Files
      • Troubleshooting Data Files Uploads
    • Qualitative Data
      • Adding and Editing People in Qualitative Data
      • Qualitative Data
      • Ownership Data
      • Firm Overview
      • People Data
      • Master Questionnaire
    • Developer Center
      • Developer Tools Overview
  • Analytics
    • Usage Analytics
      • Content Sharing Analytics
    • Component Analytics
      • Component Analytics
      • Using X-Ray with Component Analytics
      • Templates Analytics
        • Templates Dashboard
      • Section Analytics
        • Sections Dashboard
      • Shell Analytics
        • Shells Dashboard
      • Data Block Analytics
        • Data Blocks Dashboard
  • Administration
    • Workbox
      • Workbox Basics
    • Content Type Master
      • Creating an Input File Content Type
      • Understanding Purpose in Content Types
      • Content Groups
      • Creating Content Types
      • Content Classes
      • Content Filename Aliases
    • Users
      • Work Group Basics
      • Internal Users
        • Internal User Roles & Responsibilities
        • Manually Creating Users in Assette
        • Reset or Unlock User’s Accounts
        • SSO Internal User Roles & Tasks
      • Work Groups
        • Creating & Editing Work Groups
        • Creating Subgroups
    • Workflows
      • Workflows Basics
      • Workflow Frequently Asked Questions (FAQ)
      • Workflow Management
        • Workflow Management Overview
        • Workflow Reassignment
      • Workflow Design
        • Client Portal User Approval Workflow
        • Editing or Deleting a Workflow
        • Creating a Workflow
        • Creating Conditional Workflows
    • Product Master
      • Composite vs. Rep Accounts
      • Product Master Overview
      • Deactivating & Deleting Products
      • Troubleshooting Product Master Errors
    • Classification Master
      • Classification Master Overview
      • How to Manage Content Classifications
      • Creating & Managing Labels
      • Labels
      • Limitations
      • Compliance Tags
      • Data Ingredients Overview
    • Configurations
      • Attribution Data Objects Configurations
  • Client Portal
    • Security Overview for the Assette Client Portal
    • Client Portal Overview
    • Creating Notifications for Client Portal Users
    • Client Portal Users
      • Client Portal Frequently Asked Questions (FAQ)
      • Client Portal Session Handling
      • Log into the Assette Client Portal
      • Managing User Access in the Client Portal
      • Creating a New Portal User
      • Editing or Creating Portal Users
      • Deleting a Client Portal User
      • Monitoring and Accessing User Login Activity for Client Portal
  • Tutorials
    • When to Create a New Artefact in Assette
    • Creating a Fixed-Row Zigzag Table
  • Legacy Support
    • Assette Centers [Legacy]
    • Data Validations [Legacy]
    • Assette Roles Overview [Legacy]
    • Create & Manage Attributes [Legacy]
    • Internal Users Management [Legacy]
    • Legacy Authoring Center
      • Data Object Library [Legacy]
      • Data Docs [Legacy]
      • Smart Shells [Legacy]
      • How to Create a New Smart Page [Legacy]
      • Legacy Smart Pages
        • Creating and Editing Smart Pages [Legacy]
      • Legacy Smart Docs
        • Creating a Smart Doc [Legacy]

Developers

202
  • Getting Started
    • The Assette Navigation Bar
    • User Login & Creation
      • Add Assette Users with Azure AD
      • Developer Roles & Permissions
      • How to Create & Assign Permission Groups
      • Permission Groups Overview
    • Implementation Overview
      • Introduction to Assette Implementation
      • The Assette Implementation Approach
      • What Data is Required to Start?
      • Connecting to Source Systems with Assette
      • Essential Data Blocks
      • Fields Synchronized with Assette
  • Developer Tools
    • Tool Setup
      • Assette Development Stack
      • Developer Center Configurations
      • Prohibited Data Block Keywords and Built-ins
      • Master Data Scheduler
      • Python Data Block Libraries & Keywords
      • Troubleshooting
        • Troubleshooting AxiosError-500 Errors
        • Assette VS Code Extension Troubleshooting
      • Visual Studio Code
        • Assette Visual Studio Code Extension
        • How to Find Where a Component is Used in the VS Code Extension
        • Error and Status Messages Reference
        • Signing Into the Assette VS Code Extension
        • VS Code Frequently Asked Questions (FAQs)
        • Installing the Assette Block Editor VS Code Extension
        • Assette VS Code Extension Troubleshooting
    • Data Block Editor
      • Using Nested Functions in Data Blocks
      • Importing Python Libraries
      • Import & Export Data Blocks
      • Data Block Unit Testing in Python
      • Data Block Editor Basics
        • Introduction to the Data Block Editor
        • Calculation Operators and Precedence
        • Secret Management
        • How to Copy & Delete Data Blocks
        • Creating & Editing Data Blocks
        • How to Freeze Data Blocks
      • Data Block Keywords
        • Understanding the “response” Keyword in Assette Data Blocks
        • Understanding the ‘read’ Keyword in Assette Data Blocks
      • Data Block Editor Metadata
        • How to Update Data Block Metadata
      • Data Block Editor Troubleshooting
        • Troubleshooting API Authentication Issues
    • Data Object Editor
      • Applying Row Filtration with Data Objects
      • Locking a Data Object
      • Introduction to the Data Object Editor
      • Dynamic Row Numbering
      • Force Unlocking a Data Object
      • Editing Data Objects
      • Creating Data Objects
      • Data Object KeyError
      • How to Copy & Delete Data Objects
      • Generation Time Data Settings
      • Importing & Exporting Data Objects
      • Design View
        • Data Settings Tab
          • Data Settings Tab
        • General Info Tab
          • General Info
          • Styling Classes
        • Data Source Tab
          • Data Source Tab
        • Columns Tab
          • Columns Tab
          • Date Formats
        • Groupings Tab
          • Grouping Tab
          • Group Expressions & Group Ordering
          • Creating Group Header Rows
          • Creating Group Summary Rows
          • How to Create “Group By” Data Settings
        • Sorting Tab
          • Sorting Tab
        • Summary Tab
          • Summary Tab
        • Row Types Tab
          • Row Types Tab
        • Title & Footnotes Tab
          • Title & Footnotes Tab
        • Legend Tab
          • Legend Tab
        • Output Variables Tab
          • Output Variable Tab
        • Internal Variables Tab
          • Internal Variables
          • Internal Variable Type Assignment
        • No Data Message Tab
          • No Data Message Tab
      • Expressions
        • The “round(value, n)” Expression
        • Expressions, Operators, & Functions
        • The “Contains()” Function
        • The “HasValue()” Function
        • The “NOT” Operator
        • The “OR” Operator
        • The “<> Not Equal To” Operator
        • The “>= Greater Than or Equal To” Operator
        • The “ADD” Expression
        • The “AND” Expression
        • The “Divide” Expression
        • The “Minus” Expression
        • The “Multiply” Expression
        • The “<= Less Than or Equal to” Operator
        • The > Greater Than Operator
        • The “==” Equals Operator
        • The Grouping Operator “()”
        • The < Less Than Operator
    • Dynamic Fields
      • Dynamic Fields
    • Footnote Editor
      • Footnote X-Ray View
      • Footnote Editor
      • How to Create & Edit Footnotes
      • Import Variables & Columns
    • Tenant Manager
      • Deployment Statuses
      • Tenant Manager Overview
      • Deploy Content Using the Assette Tenant Manager
      • Review Artifacts
      • Tenant Manager Troubleshooting
      • Tenants in the Tenant Manager
      • Deployment Processing & Error Logging
  • Data Blocks
    • Data Block Basics
      • Publishing Data Blocks
      • Data Block Basics
      • Data Block Categories
      • Data Block Request Parameters
    • Account Master
      • Account Master Data Block
      • Filtering the Account Master Using Account Codes
    • Data Blocks by Category
      • Understanding Assette Data Blocks
      • System Data Blocks
        • Organization Add Data Block
        • Organization Master Data Block
        • Get Recipient Info Salesforce Transform Data Block
        • Get Recipient Info Salesforce Data Blocks
        • Get Recipients LocalDB Data Block
        • Get Recipient Info Local Data Block
        • Recipient Master Data Block
        • Attribute Type Values Local Data Block
        • Brand Theme Selector Data Block
        • Brand Theme Extract Data Block
        • System Data Blocks Overview
        • Account Master Data Block
        • Asset Classes Local Data Block
        • As of Dates Data Block
        • Countries Data Block
        • Currency Codes Data Blocks
        • Product Master Data Block
        • Sub Accounts Client Database Data Block
        • Sub Accounts Local Database Data Block
        • Sector Schemes Data Blocks
        • Sectors Data Block
        • Sub Accounts Data Block
      • Sync Data Blocks
        • Sync Data Block Overview
        • Country List Sync Data Block
        • Product Master Sync Data Block
        • Attribute Type Values Sync Data Block
      • Source Data Blocks
        • Source Product Offer Countries Data Block
        • Source Sub-Accounts Relationship Data Block
        • Source List of Attribute Type Values Data Block
        • Source Extract Accounts Details Data Block
        • Source Account Attributes Values Data Block
        • Source List of Currency Codes Data Block
        • Source Product Master Extract Data Block
      • Transform Data Blocks
        • Assette Get Valid Periods Data Block
        • System Period Information Data Block
        • Assette Get Begin & End Date Data Block
        • Source Extract Accounts Details Data Block
      • Interface Data Blocks
        • Organization Read Local Data Block
        • Sectors Local Database Data Block
        • Assette Period Code Map Data Block
        • Account Attribute Mapping Local Database Data Block
        • Account Attributes Local Database Data Block
        • Source Product Master Extract Data Block
        • Source List of Currency Codes Data Block
        • Source Account Attributes Values Data Block
        • Product Master Local Data Base Data Block
      • Configuration Data Blocks
        • Salesforce Settings Data Block
        • Configuration Data Block Overview
        • Calculation Python Environment Data Block
        • Python Data Calculation Modules Data Block
        • Python Environment for Date Calculation Data Block
        • Demo Snowflake Setting Data Block
        • Snowflake Demo Certificate Data Block
        • Calculation Environment Data Block
    • Data Blocks by Functionality
      • Get Major Minor Ticker Data Block
  • Data Objects
    • Data Objects
    • Data Object X-Ray View
    • Introduction to Data Objects
  • Integrations
    • Connecting Salesforce with Assette
    • Snowflake
      • Source Account Attributes Values Data Block
      • Snowflake Integration
    • Aprimo
      • Assette-Aprimo Integration Overview
      • Inserting Content with Aprimo
      • Aprimo Image Library Data Block
      • Aprimo Thumbnail Image Library API Data Block
      • Modifying the Aprimo API Records Data Block
      • Aprimo Data Blocks
        • Aprimo API Post Order Data Block
        • Aprimo Image Thumbnail Data Block
        • Aprimo API Single Record Data Block
        • Aprimo API Records Data Block
        • Aprimo API Order Status
        • Image Content Data Block
  • Developer FAQ
    • Batch Generation Architecture
    • How to Add a New Product to the Product Master
    • How to Add New Attributes to the Attribute Master
    • Data Blocks Frequently Asked Questions (FAQ)
    • Data Object Frequently Asked Questions (FAQ)
    • Tenant Manager Frequently Asked Questions (FAQ)
    • TLS Email Encryption via SendGrid
    • Data Block Cheat Sheet
    • Why Can’t I Edit a Data Object?
    • How Do Unit Tests Work in Assette?
    • Enable Assette Add-In in Case of Failure
    • How Do I Log into Snowflake?
    • Period Codes
    • Developer Tools FAQs
      • Removing Blank or NULL Columns
      • How to Display Different Values in the Account Code Dropdown in the Data Object Editor Preview
      • When and Why You See an Impact Change Message in the Developer Center
  • Tutorials
    • Creating a Correlation Matrix Table
    • Data Block Tutorials
      • Structuring Data for Time-Series Charts in PowerPoint
      • How to Cache Data Using Data Blocks
      • Creating a Certificate Data Block
      • Making Public API Calls Using Assette Data Blocks
      • Using Data Blocks to Make API Calls
    • Data Object Tutorials
      • Creating Dynamic Column Headings
implementation

Implementation

18
  • Getting Started
    • Welcome to the Assette Implementation Guide
  • Planning Your Implementation
    • Assette 101
    • The Three Layer Model
    • What to Expect from Implementation
  • Platform Layers
    • The Data Engine
    • Authoring Center
    • Content Hub
  • Assemble Your Implementation Team
    • Technical Environment & Tenant Setup
    • Building Your Implementation Dream Team
    • Scaling Your Implementation Across Strategies & Modules
  • Working With Data
    • Content Inputs
    • Prepare and Shape Your Data
    • Real-Word Examples
  • Implementation Process & Support
    • How ACE Training Works
    • Implementation Steps
    • Analyze Backward, Build Forward
    • Assette Support & Roles
    • ACE Syllabus
  • Home
  • Docs
  • Developers
  • Data Blocks
  • Data Blocks by Category
  • Transform Data Blocks
  • Assette Get Begin & End Date Data Block

Assette Get Begin & End Date Data Block

17 min read

The Assette Get Begin & End Date (ast_fn_GetBeginEndDates) Data Block is a Demo Data Block and may be edited.

The Assette Get Begin & End Date (ast_fn_GetBeginEndDates) Data Block is a Demo Data Block which processes different period codes, such as MTD, QTD, YTD, etc., and calculates the appropriate begin_date and end_date for each code. It reads the period universe data and uses various date patterns and logic to determine the start and end dates for a given period code. After calculating the dates, the Assette Get Begin & End Date (ast_fn_GetBeginEndDates) Data Block formats them and returns the result. As an open-source demo Data Block, this Data Block may be edited as needed.

Period Code:
The period code is retrieved from the parameter “PeriodCode” and used to determine which time period to calculate (e.g., MTD, QTD, YTD, etc.).

AsOfDate:
The date from which the period calculations are based is retrieved from parameter “AsofDate”.

Period Universe:
A dictionary of predefined period is read from the System Period Information (sys_period_information) Data Block.



Based on the PeriodCode, various date ranges are calculated using datetime and calendar to determine the start (period_begin_date) and end (period_end_date) dates. The logic handles multiple period codes like MTD (Month-to-Date), QTD (Quarter-to-Date), YTD (Year-to-Date), fiscal periods (FYTD, MRQ), prior quarters (PQ1, PQ2), prior years (PY1, PY2), and inception-to-date (ITD). Depending on the period code, specific adjustments are made to month, year, and day values to compute the correct date range.

General Info #

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

FieldValue
Nameast_fn_GetBeginEndDates
Block CategoryTransform
Block TypePython
Data CategoryNone
Output TypeData Table
EditableTrue

Dependencies #

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

Data BlockDescription
Calculation_Python_EnvThe Imports (Imports) Data Block defines the required Python libraries to be imported for the script. Each library is imported with or without an alias, depending on its usage within the code. This Data Block ensures that the necessary libraries are available for handling data manipulation, date operations, JSON parsing, and other tasks. This Data Block is not edited. [Link]
PythonEnvForDateCalculationThe Python Environment for Date Calculation (PythonEnvForDateCalculation) Data Block is used to import Python libraries and modules for date calculations. [Link]
sys_period_informationThe System Period Information (sys_period_information) Data Block defines a set of periods using period codes and their respective details, such as the display name, number of years, months, and quarters for each period. Each period is categorized based on its duration, such as month-to-date, quarter-to-date, year-to-date, prior years, or prior quarters. This Data Block is used to manage the calculation and display of time periods for various financial or reporting purposes. This Data Block is open-source and may be edited as needed. [Link]

Columns #

The following columns are the default columns for the Data Object, all columns are optional unless marked otherwise. Please see footnotes for additional information.

NameData TypeExampleDescription
begin_dateDate2020-10-31The begin date for the given period
end_dateDate2021-01-31The end date for the given period
* Indicates a mandatory column

Example Definition #

period_universe = read("sys_period_information")
# print(period_universe)
date_pattern = ""
period_code = params["PeriodCode"].strip()
as_of_date = params["AsofDate"]
if "DatePattern" in params.keys():
    date_pattern = params["DatePattern"].strip()

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

period_begin_date = as_of_date
period_end_date = as_of_date

date_obj_begin = datetime.datetime.strptime(as_of_date, date_pattern)
date_obj_end = datetime.datetime.strptime(as_of_date, date_pattern)

if period_code == "MTD":
    month = date_obj_begin.month
    period_begin_year = date_obj_begin.year
    period_begin_month = month - 1
    if period_begin_month <= 0:
        period_begin_month = 12 + period_begin_month
        period_begin_year = date_obj_begin.year - 1

    res = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res)
    period_end_date = date_obj_end

if period_code == "QTD":
    month = date_obj_begin.month
    year = date_obj_begin.year
    period_begin_month = month
    period_begin_year = year

    if month <= 3:
        period_begin_month = 12
        period_begin_year = year - 1
    elif 3 < month <= 6:
        period_begin_month = 3
    elif 6 < month <= 9:
        period_begin_month = 6
    elif 9 < month <= 12:
        period_begin_month = 9

    res = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res)
    period_end_date = date_obj_end

if period_code == "YTD":
    year = date_obj_begin.year
    period_begin_month = 12
    period_begin_year = year - 1

    res = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res)
    period_end_date = date_obj_end

if period_code == "MRQ":
    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_month = month
    period_begin_year = year

    period_end_month = month
    period_end_year = year

    if (month <= 2 and day <= 31) or (month == 3 and day < 30):
        period_begin_month = 9
        period_end_month = 12
        period_begin_year = year - 1
        period_end_year = year - 1

    elif (3 <= month <= 5 and day <= 31) or (month == 6 and day < 30):
        period_begin_month = 12
        period_end_month = 3
        period_begin_year = year - 1

    elif (6 <= month <= 8 and day <= 31) or (month == 9 and day < 29):
        period_begin_month = 3
        period_end_month = 6

    elif (9 <= month <= 11 and day <= 30) or (month == 12 and day < 30):
        period_begin_month = 6
        period_end_month = 9

    elif month == 12 and day == 31:
        period_begin_month = 9
        period_end_month = 12

    res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
    res_end = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)
    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res_begin)
    period_end_date = date_obj_end.replace(year=period_end_year, month=period_end_month, day=res_end)

if period_code.startswith("PQ"):
    period_details = period_universe[period_code]
    num_quarters = int(period_details['Quarters'])

    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_month = month
    period_begin_year = year

    period_end_month = month
    period_end_year = year

    month_delta = num_quarters * 3

    # Calculate MRQ Begin and end dates
    if (month <= 2 and day <= 31) or (month == 3 and day < 30):
        period_begin_month = 9
        period_end_month = 12
        period_begin_year = year - 1
        period_end_year = year - 1

    elif (3 <= month <= 5 and day <= 31) or (month == 6 and day < 30):
        period_begin_month = 12
        period_end_month = 3
        period_begin_year = year - 1

    elif (6 <= month <= 8 and day <= 31) or (month == 9 and day < 29):
        period_begin_month = 3
        period_end_month = 6

    elif (9 <= month <= 11 and day <= 30) or (month == 12 and day < 30):
        period_begin_month = 6
        period_end_month = 9

    elif month == 12 and day == 31:
        period_begin_month = 9
        period_end_month = 12

    res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
    res_end = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)
    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res_begin)
    period_end_date = date_obj_end.replace(year=period_end_year, month=period_end_month, day=res_end)
    ####

    begin_year = period_begin_date.year
    begin_month = period_begin_date.month

    end_year = period_end_date.year
    end_month = period_end_date.month

    begin_month = begin_month - month_delta
    end_month = end_month - month_delta

    if begin_month <= 0:
        begin_month = 12 + begin_month
        begin_year = begin_year - 1

    if end_month <= 0:
        end_month = 12 + end_month
        end_year = end_year - 1

    begin_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(begin_year, begin_month)], 30)
    end_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(end_year, end_month)], 30)

    period_begin_date = date_obj_begin.replace(year=begin_year, month=begin_month, day=begin_day)
    period_end_date = date_obj_end.replace(year=end_year, month=end_month, day=end_day)

if period_code.startswith("PY"):
    period_details = period_universe[period_code]
    num_years = int(period_details['Years'])

    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_year = year
    period_begin_month = month

    period_end_year = year
    period_end_month = month
    period_end_day = day

    if period_end_month == 12 and period_end_day == 31:
        period_begin_year -= (num_years + 1)
        period_end_year -= num_years
    else:
        period_begin_year -= (num_years + 2)
        period_end_year -= (num_years + 1)
        period_begin_month = 12
        period_end_month = 12

    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=31)
    period_end_date = date_obj_end.replace(year=period_end_year, month=period_end_month, day=31)

if period_code == "MRFQ":
    month = date_obj_begin.month
    year = date_obj_begin.year

    period_begin_year = year
    period_end_year = year

    fiscal_year_end = params["FiscalYearEnd"]
    fiscal_year_end_obj = datetime.datetime.strptime(fiscal_year_end, '%m-%d')

    fiscal_quarter_end_list = []

    for delta in range(1, 5):
        ym = fiscal_year_end_obj.month + 3*delta
        if ym > 12:
            ym = ym - 12
        fiscal_quarter_end_list.append(ym)

    most_recent_fiscal_quarter_end_month = fiscal_year_end_obj.month
    for item in fiscal_quarter_end_list:
        for i in range(1,4):
            temp_month = item + i
            if temp_month > 12:
                temp_month = 12 - temp_month
                if temp_month == month:
                    most_recent_fiscal_quarter_end_month = temp_month
                    period_end_year = year - 1
            elif temp_month == month:
                most_recent_fiscal_quarter_end_month = item

    most_recent_fiscal_quarter_begin_month = most_recent_fiscal_quarter_end_month - 3

    if most_recent_fiscal_quarter_begin_month <= 0:
        most_recent_fiscal_quarter_begin_month = most_recent_fiscal_quarter_begin_month + 12
        period_begin_year = period_begin_year - 1

    res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, most_recent_fiscal_quarter_begin_month)], 30)
    res_end = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, most_recent_fiscal_quarter_end_month)], 30)

    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=most_recent_fiscal_quarter_begin_month, day=res_begin)
    period_end_date = date_obj_end.replace(year=period_end_year, month=most_recent_fiscal_quarter_end_month, day=res_end)

if period_code.startswith("PFQ"):
    # Calculate most recent fiscal quarter first
    month = date_obj_begin.month
    year = date_obj_begin.year

    period_begin_year = year
    period_end_year = year

    fiscal_year_end = params["FiscalYearEnd"]
    fiscal_year_end_obj = datetime.datetime.strptime(fiscal_year_end, '%m-%d')

    fiscal_quarter_end_list = []

    for delta in range(1, 5):
        ym = fiscal_year_end_obj.month + 3 * delta
        if ym > 12:
            ym = ym - 12
        fiscal_quarter_end_list.append(ym)

    most_recent_fiscal_quarter_end_month = fiscal_year_end_obj.month
    for item in fiscal_quarter_end_list:
        for i in range(1, 4):
            temp_month = item + i
            if temp_month > 12:
                temp_month = 12 - temp_month
                if temp_month == month:
                    most_recent_fiscal_quarter_end_month = temp_month
                    period_end_year = year - 1
            elif temp_month == month:
                most_recent_fiscal_quarter_end_month = item

    most_recent_fiscal_quarter_begin_month = most_recent_fiscal_quarter_end_month - 3

    if most_recent_fiscal_quarter_begin_month <= 0:
        most_recent_fiscal_quarter_begin_month += 12
        period_begin_year = period_begin_year - 1

    ###
    ## Calculate the prior fiscal quarter periods
    period_details = period_universe[period_code]
    num_quarters = int(period_details['Quarters'])

    most_recent_fiscal_quarter_end_month = most_recent_fiscal_quarter_end_month - 3*num_quarters
    if most_recent_fiscal_quarter_end_month <=0 :
        most_recent_fiscal_quarter_end_month += 12
        period_end_year -= 1

    most_recent_fiscal_quarter_begin_month = most_recent_fiscal_quarter_end_month - 3
    if most_recent_fiscal_quarter_begin_month <=0 :
        most_recent_fiscal_quarter_begin_month += 12
        period_begin_year -= 1

    res_begin = ft.reduce(lambda x, y: y[1],
                            [calendar.monthrange(period_begin_year, most_recent_fiscal_quarter_begin_month)], 30)
    res_end = ft.reduce(lambda x, y: y[1],
                        [calendar.monthrange(period_end_year, most_recent_fiscal_quarter_end_month)], 30)

    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=most_recent_fiscal_quarter_begin_month,
                                                day=res_begin)
    period_end_date = date_obj_end.replace(year=period_end_year, month=most_recent_fiscal_quarter_end_month,
                                            day=res_end)


if period_code.startswith("PFY"):
    period_details = period_universe[period_code]
    num_years = int(period_details['Years'])

    fiscal_year_end = params["FiscalYearEnd"]
    fiscal_year_end_obj = datetime.datetime.strptime(fiscal_year_end, '%m-%d')

    year = date_obj_begin.year

    begin_year = year - num_years - 1
    begin_month = fiscal_year_end_obj.month

    end_year = year - num_years
    end_month = fiscal_year_end_obj.month

    end_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(end_year, end_month)], 30)

    period_begin_date = date_obj_begin.replace(year=begin_year, month=begin_month, day=end_day)
    period_end_date = date_obj_end.replace(year=end_year, month=end_month, day=end_day)

if period_code == "FYTD":
    month = date_obj_begin.month
    year = date_obj_begin.year

    fiscal_year_end = params["FiscalYearEnd"]
    fiscal_year_end_obj = datetime.datetime.strptime(fiscal_year_end, '%m-%d')

    period_begin_month = fiscal_year_end_obj.month
    period_begin_day = fiscal_year_end_obj.day
    period_begin_year = year

    period_end_month = month
    if period_end_month <= period_begin_month:
        period_begin_year = year - 1

    period_begin_date = date_obj_begin.replace(year = period_begin_year, month = period_begin_month, day = period_begin_day)
    period_end_date = date_obj_end

if period_code.endswith("MT"):
    period_details = period_universe[period_code]
    num_months = int(period_details['Months'])

    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_month = month
    period_begin_year = year

    period_end_month = month
    period_end_year = year

    res_end = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)
    if res_end == day:
        period_begin_month = period_begin_month - num_months
        if period_begin_month <= 0:
            period_begin_year = period_begin_year - 1
            period_begin_month = 12 + period_begin_month
        res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res_begin)
    else:
        period_begin_month = period_begin_month - num_months
        if period_begin_month <= 0:
            period_begin_year = period_begin_year - 1
            period_begin_month = 12 + period_begin_month
        res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        if period_begin_month == 2:
            if day > res_begin:
                period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                            day=res_begin)
            else:
                period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                            day=day)
        else:
            period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                            day=day)
    period_end_date = date_obj_end

if period_code.endswith("YC") or period_code.endswith("YA"):
    period_details = period_universe[period_code]
    num_years = int(period_details['Years'])

    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_month = month
    period_begin_year = year

    period_end_month = month
    period_end_year = year

    res_end = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)
    if res_end == day:
        period_begin_year = period_begin_year - num_years
        res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month, day=res_begin)
    else:
        period_begin_year = period_begin_year - num_years
        res_begin = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        if period_begin_month == 2:
            if day > res_begin:
                period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                            day=res_begin)
            else:
                period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                            day=day)
        else:
            period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                        day=day)
    period_end_date = date_obj_end

if period_code == "ITDA" or period_code == "ITD":
    date_obj_begin = datetime.datetime.strptime(params["InceptionDate"], '%Y-%m-%d')
    period_begin_date = date_obj_begin
    period_end_date = date_obj_end

if period_code.startswith("MRM"):
    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_month = month
    period_begin_year = year

    period_end_month = month
    period_end_year = year
    period_end_day = day

    if period_end_day == ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30):
        period_begin_month -= 1
        if period_begin_month == 0:
            period_begin_year -= 1
            period_begin_month = 12
        period_begin_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_begin_year, period_begin_month)], 30)
    else:
        period_begin_month -= 2
        period_end_month -= 1
        if period_begin_month <= 0:
            period_begin_year -= 1
            period_begin_month = 12 + period_begin_month
        period_begin_day = ft.reduce(lambda x, y: y[1],
                                        [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        if period_end_month == 0:
            period_end_year -= 1
            period_end_month = 12
        period_end_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)

    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                day=period_begin_day)
    period_end_date = date_obj_end.replace(year=period_end_year, month=period_end_month,
                                                day=period_end_day)

if period_code.startswith("PM"):
    period_details = period_universe[period_code]
    num_months = int(period_details['Months'])

    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_month = month
    period_begin_year = year

    period_end_month = month
    period_end_year = year
    period_end_day = day

    if period_end_day == ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30):
        period_begin_month -= (num_months + 1)
        period_end_month -= (num_months)
        if period_begin_month <= 0:
            period_begin_year -= 1
            period_begin_month += 12
        period_begin_day = ft.reduce(lambda x, y: y[1],
                                        [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        if period_end_month <= 0:
            period_end_year -= 1
            period_end_month = 12
        period_end_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)
    else:
        period_begin_month -= (num_months + 2)
        period_end_month -= (num_months + 1)
        if period_begin_month <= 0:
            period_begin_year -= 1
            period_begin_month = 12 + period_begin_month
        period_begin_day = ft.reduce(lambda x, y: y[1],
                                        [calendar.monthrange(period_begin_year, period_begin_month)], 30)
        if period_end_month == 0:
            period_end_year -= 1
            period_end_month = 12
        period_end_day = ft.reduce(lambda x, y: y[1], [calendar.monthrange(period_end_year, period_end_month)], 30)

    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                day=period_begin_day)
    period_end_date = date_obj_end.replace(year=period_end_year, month=period_end_month,
                                            day=period_end_day)
if period_code.startswith("MRY"):
    month = date_obj_begin.month
    year = date_obj_begin.year
    day = date_obj_begin.day

    period_begin_year = year
    period_begin_month = month

    period_end_year = year
    period_end_month = month
    period_end_day = day

    if period_end_month == 12 and period_end_day == 31:
        period_begin_year -= 1
    else:
        period_begin_year -= 2
        period_end_year -= 1
        period_begin_month = 12
        period_end_month = 12

    period_begin_date = date_obj_begin.replace(year=period_begin_year, month=period_begin_month,
                                                day=31)
    period_end_date = date_obj_end.replace(year=period_end_year, month=period_end_month,
                                            day=31)
period_begin_date = period_begin_date.strftime('%Y-%m-%d')
period_end_date = period_end_date.strftime('%Y-%m-%d')

response['data'] = [{"begin_date": period_begin_date, "end_date": period_end_date}]

Example Request #

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

{
    "AsofDate": "2021-05-31",
    "PeriodCode":"PFQ1",
    "FiscalYearEnd": "04-30",
    "InceptionDate": "2015-09-08",
    "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": [
        {
            "begin_date": "2020-10-31",
            "end_date": "2021-01-31"
        }
    ],
    "errors": [],
    "success": true,
    "logs": []
}
System Period Information Data BlockSource Extract Accounts Details Data Block
Still stuck? How can we help?

How can we help?

Updated on September 24, 2024
Page Index
  • General Info
  • Dependencies
  • Columns
  • Example Definition
  • Example Request
  • Example Response
  • Platform
  • Modules
  • AssetteAI
  • Who We Are
  • Who We Work With
  • Platform
  • Modules
  • AssetteAI
  • Who We Are
  • Who We Work With
  • Platform
  • Modules
  • AssetteAI
  • Who We Are
  • Who We Work With
  • Platform
  • Modules
  • AssetteAI
  • Who We Are
  • Who We Work With
  • Blog
  • News
  • Events
  • Contact
  • Blog
  • News
  • Events
  • Contact
  • Blog
  • News
  • Events
  • Contact
  • Blog
  • News
  • Events
  • Contact
X-twitter Linkedin Youtube

4 Faneuil Hall, 4th Floor
Boston, MA
02109 USA
Tel: +1.617.723.6161

Book a Demo
  • Privacy Policy
  • © 2025 Assette. All Rights Reserved
  • Powered By Artrivo (PVT) Ltd.