Data label showing date range from calendar range filter

I am trying to show a data label or data labels that would display the date range as it is selected in a filter. I have found some Cube topics covering how to do this with a value filter, but I don’t understand how to apply this to my case and how to get both the “From” date and the “To” date. I’m also not sure how to apply a script to a data label in general.
Thanks!

Hello,

The answer to this can be fairly simple or quite complicated depending on how many cases you want to handle. I’ll give the answer to the most simple case, and advice for how you could go further if you want to handle all the cases we have to in the product.

First I don’t think you should use a dataLabel, but instead just use a regular label (components->label). After you add one, you need to know which view parameter is connected to the calendar range control. You can find them in the ‘PARAMETERS’ tab at the bottom usually. If you double click the one you know is being used, you can find the ‘Id’ property and copy the Id. Then you can use the following script, such as on the click of a button or ‘Parameter Value Changed’ of the parameter control in order to populate the label:

var pv = this.parentView.control.getViewParameterById("YOUR_VIEW_PARAMETER_ID_HERE").parameterValue;
if (pv.lowerBoundaryValue && pv.upperBoundaryValue) {
  label1.labelText = "From: " + Globalize.format(pv.lowerBoundaryValue.memberTime, "D") + ", to: " + Globalize.format(pv.upperBoundaryValue.memberTime, "D"); 
}

There are 2 caveats with this code. First, it won’t work with tokens. If the user selects ‘End of Today’ or something like this, it will not be able to populate. Secondly the formatting used are via JavaScript, and you can look at the various available format strings here. But this may not be the same as how the calendar shows the date, as it’s using member formatting from the time dimension.

If you need to support tokens as well, then you’ll need to use the parameterValue.resolve method. This method will return you (async) another parameter value which has the upper and lower boundary value’s populate with ‘real’ members that also have memberTime (instead of the token).

If you need to support the exact formatting the calendar control uses then you need to not use memberTime, and instead use the hierarchy member. In order to do that, you’d need to use the hierarchyService.getMember method to get the associated member from lowerBoundaryValue (and upper). It requires some IDs that you’d need to know beforehand, such as the metric set ID and the hierarchy unique name. It will return a member which will have a caption on it that is identical to what the calendar shows.

1 Like