language
Call Us: 1-800-497-0151

Blog

Create list of Months in OneStream

  • , Consultant

There are times in OneStream when you need to pull a list of time to help facilitate the execution of data management job or even produce a set number of periods on a cube view. To have the ability to set a time frame, you may have to create a list of time based on a selected number of periods. Sometimes a standard Member Filter expansion may help but other times, the users may want to have the flexibility to select the number of months they want to see.

In this post, we'll explore a code snippet that helps generate a list of months based on user selection of number of months to forecast. This code is particularly useful in financial forecasting scenarios, where we need to calculate values for a number of specific months.

What Does the Code Do?

The code is designed to generate a list of months starting from a specific month, based on a selected scenario and selected number of months. It then returns that list, which can be used in further calculations or displayed in a report.

Step 1: Getting the Initial Month

The code begins by retrieving the Scenario value based off a selected scenario parameter that gives the users a list of scenarios to choose from. If the scenario selected is “Forecast” then the code retrieves the Global Time that is set in the application. Otherwise, it will retrieve the starting month from the scenario's text field 1. For this blog, we will just use the Forecast scenario as a starting point so Global Time will be used and set at 2024M8.

Step 2: User-Selected Number of Months

The user will also have to select the number of forecast months from a parameter list which gives them an option of 6, 12, 24 or 36 (This is set using a delimited list parameter and any number of months can be used). This represents how many months the user wants to include in the forecast. This number will determine how many months are generated in the list.

Step 3: Generating the List of Months

With the starting month and the number of months in hand, the code calls a function named GenerateMonthList. This function is where the magic happens.

Inside GenerateMonthList, the code does the following:

  • 1. Parse the Start Month: It reads the start month as a year and month, like 2024M8 for August 2024.
  • 2. Add the Initial Month: The start month is added to the list first.
  • 3. Loop Through Months: The code then loops through the number of months the user requested.

For each iteration, it adds a month to the list. If the month exceeds 12 (December), the code rolls over to the next year and starts counting from January.

For example, if the Global 2024M8, and the user requested 6 months, the list will include:

  • • T#2024M8 (August 2024)
  • • T#2024M9 (September 2024)
  • • T#2024M10 (October 2024)
  • • T#2024M11 (November 2024)
  • • T#2024M12 (December 2024)
  • • T#2025M1 (January 2025)
  • • T#2025M2 (February 2025)

Step 4: Returning the Result

Finally, the code joins the list of months into a single string and returns it. This result can then be used elsewhere in the application, such as in reports or further calculations.

This code is a powerful tool for automating the generation of month sequences in forecasting scenarios. It dynamically adapts to different scenarios and user inputs, ensuring that the correct months are always calculated and returned.

Hopefully, this breakdown has helped you understand how the code works and how it can be applied in real-world scenarios! Below is a snippet of the code used:


Create List of Months

Contact MindStream Analytics

Want to learn more about OneStream Software? Please complete the form below and we'll get back to you shortly.


Partner SpotLight

OneStream Diamond Partner

OneStream CPM

OneStream aligns to your business needs and changes more quickly and easily than any other product by offering one platform and one model for all financial CPM solutions. OneStream employs Guided Workflows, validations and flexible mapping to deliver data quality confidence for all collections and analysis while reducing risk throughout the entire auditable financial process.

OneStream Profile