Itay Regev
Itay Regev

Reputation: 191

IcCube reporting preselected dates in date slicer

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

enter image description here

Upvotes: 3

Views: 101

Answers (2)

ic3
ic3

Reputation: 7680

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.

Upvotes: 2

Artem Lopatiy
Artem Lopatiy

Reputation: 938

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.

Upvotes: 1

Related Questions