How to build Dynamic Today, current month, Previous Month etc. in Pyramid Formulate
How to build Dynamic Today, current month, Previous Month etc. in Formulate
Get Dynamic Dates Using Formulate Wizard.
To make the access on the latest information, it often makes sense to have a dynamic member or list that will always be “today”, or “current month” etc. within the time dimension.
One way that we can achieve this, is using the exists function on a fact where the latest date is typically the last date of processing. In this article we will show you how to do this.
Notice: this list will bring the last date that has data in the fact table. Sometimes this is exactly what we need, meaning, we want the last date with data in a certain fact (and if it was a few days ago – no problem).
We can use the same method to find the last month with data, or the previous one (just replace the Last 1 node with last 2 and first 1).Using StrToMember on a date column
Where the Hierarchy is the Hierarchy or column, and the text is the text of the selected member.
In cases when the "exists" function does not help us to get the date we want.
e.g. if we want to show yesterday’s data, in a model that may not always have data for yesterday. In such cases we will need to use the StrToMember function. This function allows us to locate a certain member in a column or a hierarchy.
The Syntax for StrToMember is:
So for example, the following will give us the country France from the Countries dimension: If we’re trying to do it with a date column, in versions prior to 2020.27, we will need to use Epoch Time: This will bring up Jan 21st 2019. Beginning with version 2020.27, it will work with the date presented as text (in the same formatting as the column)
Convert Date to Epoch Time
The way to convert a date to epoch time will require converting a string to a date with StringToDate() and then converting to epoch time using DateToTimeStamp:
The big step forward now, is to replace the StringToDate part, with the Date() function, that returns the Current Date: This will return the date today on the Cal Date dimension (assuming it exists, of course)
And If necessary – we can use the AddDays function to show yesterday, two days ago etc.- Using StrToMember on a date hierarchy
Sometimes we will need the same calculation on a Hierarchy, rather than a column.The Name for a hierarchy member in StrToMember will be a concatenation of all the hierarchy’s levels. For example in a calendar hierarchy (Year – Quarter – Month – Date), May 2020’s unique name is: So if we want to use StrToMember we will use: And if we want something dynamic that will always show the current month we will need to use the DateFormat() function to build the entire structure:For Different levels in the hierarchy, a different string will need to be adjusted.
If you have questions about these tips (or improvements) please let us know in a comment.
Reply
Content aside
- 1 Likes
- 1 yr agoLast active
- 270Views