3

what can i put in the 'Preselection from' label to get the beginning of current month?

enter image description here

Itay Regev
  • 191
  • 8

2 Answers2

2

There is another option that doesn't need javascript and most probably will live longer. The Range selection can use values from the MDX so we can change query to get what we're looking for :

WITH
SET [dates] as [Time].[Calendar].[Day].allmembers
Function ic3Min() as Head([dates])
Function ic3Max() as Tail([dates])
Function ic3DefFrom() as Tail([dates]).dtWithDayOfMonth(1)  // first day of month , not the same as withDayOfMonth
Function ic3DefTo() as Tail([dates])
SELECT
{ic3Min(),ic3Max(),ic3DefFrom(),ic3DefTo()} on 0
FROM [Sales]
CELL PROPERTIES CELL_ORDINAL

You've a nice family of date functions in MDX that allow for navigating time. In our example , LookupByKey,Today and withDayOfMonth. Something like

[Time].[Calendar].[Day].lookupByKey( Today()->withDayOfMonth(1) )

That could be transformed into a function to be reused :

 Function  myDatesStartOfCurrentMonth() as [Time].[Calendar].[Day].lookupByKey(Today()->withDayOfMonth(1) )

Eventually you've to change the filter to use the MDX values :

enter image description here

And that should make it.

ic3
  • 7,917
  • 14
  • 67
  • 115
1

There is no possibility to set such preselection with existing data options, but you can achieve needed behavior with Widget's JavaScript Hooks.

In order to set preselection to a first day of a month:

  • Configure data options

e.g. Like in the screenshot above, but without preselection

  • Go to hooks category of widget's options

  • Copy code below to "On Data Received" hook value:

On Data Received (for icCube 6.1):

/**
 * Return data object
 */
function(context, data, $box) {
    context.fireEvent('initDate', {caption_: moment().set('date', 1).format('YYYY-MM-DD')})
    return data;
}

On Data Received (for earlier versions):

/**
 * Return data object
 */
function(context, data, $box) {
    context.eventMgr().fireEvent('initDate', {caption_: moment().set('date', 1).format('YYYY-MM-DD')})
    return data;
}
  • Configure Event Section like this:

Events Section

Update for Range Preselection

In order to apply range preselection change JavaScript body of On Data Received hook to:

 /**
 * Return data object
 */
function(context, data, $box) {
    let event = new viz.event.RangeSelectionEvent([
        {name: moment().set('date', 1).format('YYYY-MM-DD')},
        {name: moment().set('date', 2).format('YYYY-MM-DD')}
    ]);
    context.fireEvent('initDate2', event)
    return data;
}

P.S. Check Demo Report to see how it works.

Artem Lopatiy
  • 948
  • 5
  • 15
  • Thanks for the answer it was very helpful. what is the correct syntax to fire the event if i want to put both preselection from and preselection to from the Widget's JavaScript Hooks? – Itay Regev May 08 '17 at 15:45
  • @ItayRegev answer extended with range case. Hope it helps! – Artem Lopatiy May 09 '17 at 09:26