Set default value for the select component in pentaho CDE - mdx

I have 1 combobox in layout, 1 select component and 1 datasource (mdx over mondrianJndi)
Here my mdx query
with member [Measures].[Name] as '[Year].CurrentMember.UniqueName' select TopCount( filter({Descendants([Year].[All Years] ,[Year].[Year])}, not isempty(([Year].CurrentMember)) ) , 50) on ROWS,
{[Measures].[Name]} on Columns
from [Department Cube]
My query return a list of year have data (include current year)
At this time, I have to wait data loaded then set the value of combobox to the current year by js resource.
How can I set default value is current year to the combobox in layout with out wait the data loaded ?

Being a dynamic query you shouldn't rely on "current" year calculations. Any JS function to determine the current year, e.g. from the client's clock will suffer from timezone oddities and may try to set the value to something that isn't returned from the query.
You should set the default of the selector only after reading the query results, but the best place to do so is in the postFetch method of the component.
For example, if you want to set the parameter value to be the last value of the query results,
function(data){
var results = data.resultset
// some logic here to set current_year to the adequate value. For example,
current_year = results[results.length-1][0];
dashboard.setParameter(this.parameter, current_year);
return data;
}

Related

Summing the value of the aggregate function Last()

enter image description hereI am trying to design a report in ssrs that returns the last opening stock for each product in the dataset. To achieve this I used
=Last(Fields!CustProdAdj_new_openingstockValue.Value).
This works fine. But where I encountered a problem is in getting the sum of all the opening stock for each product. I tried using
=sum(Last(Fields!CustProdAdj_new_openingstockValue.Value))
but I got the error message
[Error on Preview]
Please is there another way to go about this
I have tried using aggregate(), runningValue(), to no avail
This is the dataset
This is the report layout
On previewing having used max()
This is probably easier to do directly in the dataset query but assuming you cannot change that, then this should work...
This assumes your data is ordered by the CustProdAdj_createdon column and that this is a date, datetime or some other ordered value, change this bit if required.
=SUM(
IIF(Fields!CustProdAdj_createdon.Value = Max(Fields!CustProdAdj_createdon.Value, "MyRowGroupNameHere"),
CustProdAdj_new_openingstockValue,
0)
)
Change the MyRowGroupNameHere to be the name of the rowgroup spelled exactly as it is in the rowgroup panel below the main design panel. Case sensitive and include quotes.
What this does is, for each row within the rowgroup "MyRowGroupNameHere", compare the CustProdAdj_createdon date to the max CustProdAdj_createdon across the rowgroup. . If it is the same then return the CustProdAdj_new_openingstockValue else return 0.
This will return the value required on only 1 record within the group.
For example, if you had 1 row per day then only on the last day of the month would a value be returned other than 0 because only the date of the last record would match the maximum date within the group.
Then it simply sums the results of this up.

Serial Numbering an SSRS Table with Grouping And Headers

[Report Design]
Here is an Example for a report that I am working on.
It is grouped by "CostCenter" Field and above each group there is a header with the SUM of the "Betrag" Field.
I want to Number each Column in the Table with the Headers as well.
I tried using RowNumber(Nothing) or Row Number("DataSet") Or Running Value.
I get these results [Report View]
I think there should be a way or a Formula that connects both Fields in the Colmun Row Number or "Zeilennr" that results with a Correct Row Numbering for each Row
You can almost do this. The number would not work if placed to the left of the inner group, it needs to be at the same level as the details group but it will give you the correct number. I've only done very limited testing but it seems to work.
Go to the report's properties and then to the code tab.
Now add the following custom code function
Public rn as Integer
Public Function GetRn() AS Integer
rn = rn +1
return rn
End Function
Now in the text box where you want the number to appear use the expression
=Code.GetRn
All this does in increment the public variable by 1 then return it. It has no concept of the row it lies on, so if you did not include this on a group row, the numbers would remain sequential.
Here is a demo based on a small test report I had..
Design showing the position of the expression
Gives this result
Add the same expression to more text boxes...
Give these results...

Wrapping a range of data

How would I select a rolling/wrapping* set of rows from a table?
I am trying to select a number of records (per type, 2 or 3) for each day, wrapping when I 'run out'.
Eg.
2018-03-15: YyBiz, ZzCo, AaPlace
2018-03-16: BbLocation, CcStreet, DdInc
These are rendered within a SSRS report for Dynamics CRM, so I can do light post-query operations.
Currently I get to:
2018-03-15: YyBiz, ZzCo
2018-03-16: AaPlace, BbLocation, CcStreet
First, getting a number for each record with:
SELECT name, ROW_NUMBER() OVER (PARTITION BY type ORDER BY name) as RN
FROM table
Within SSRS, I then adjust RN to reflect the number of each type I need:
OnPageNum = FLOOR((RN+num_of_type-1)/num_of_type)-1
--Shift RN to be 0-indexed.
Resulting in AaPlace, BbLocation and CcStreet having a PageNum of 0, DdInc of 1, ... YyBiz and ZzCo of 8.
Then using an SSRS Table/Matrix linked to the dataset, I set the row filter to something like:
RowFilter = MOD(DateNum, NumPages(type)) == OnPageNum
Where DateNum is essentially days since epoch, and each page has a separate table and day passed in.
At this point, it is showing only N records of type per page, but if the total number of records of a type isn't a multiple of the number of records per page of that type, there will pages with less records than required.
Is there an easier way to approach this/what's the next step?
*Wrapping such as Wraparound found in videogames, seamless resetting to 0.
To achieve this effect, I found that offsetting the RowNumber by -DateNum*num_of_type (negative for positive ordering), then modulo COUNT(type) would provide the correct "wrap around" effect.
In order to achieve the desired pagination, it then just had to be divided by num_of_type and floor'd, as below:
RowFilter: FLOOR(((RN-DateNum*num_of_type) % count(type))/num_of_type) == 0

Last Available value MDX

I have a requirement where in i am to extract data from a cube, within the SSRS dataset using the query builder ,with the time dimension in the result set, across a range of dates. The conditions are
The measures are to be displayed for each day of the date range.
The sub total row should have the last available measures value for that time range.
There is a time filter (currently a single date filter with a multi select option).
my MDX is as below.
The measure has a 'Sum' as the aggregation type.
I have a calculated measure with the scope defined as below.
SCOPE([MEASURES].[Measure1]);
SCOPE([Date].[Date].MEMBERS);
THIS = TAIL(EXISTING ([Date].[Date].MEMBERS),1).ITEM(0) ;
END SCOPE;
END SCOPE;
This above scope statement works perfectly. however, when i select in more that one date member this query slows WAYYYYYYY down. Performance numbers are
Across 1 date - 4 seconds
Across 2 dates - 22 minutes
Across 3 dates - unknown (in Hours)
This drastic degradation in performance goes away if i remove the scope statement, which makes me thing that there should be a better way to do the same. the final report query is as below.
SELECT
NON EMPTY
{[Measures].[Measure1]} ON COLUMNS
,NON EMPTY
{ [Dimension1].[Dimension1].[Dimension1].ALLMEMBERS*
[Dimension2].[Dimension2].[Dimension2].ALLMEMBERS*
[Dimension3].[Dimension3].[Dimension3].ALLMEMBERS*
[Date].[Date].[Date].ALLMEMBERS
} ON ROWS
FROM (
SELECT {[Date].[Date].&[2014-06-13T00:00:00]
,[Date].[Date].&[2014-06-16T00:00:00] } ON COLUMNS
FROM [Cube]
)
So the question again is, Is there a way to do the last available value part of the scope statement so as to have a better performance? Also, if there is another way to write the final mdx that would help the performance?.
Please let me know if there are anythings unclear regarding the question.
Thanks
Srikanth
The first optimization step would be to change your query to
SELECT
NON EMPTY
{[Measures].[Measure1]} ON COLUMNS
,NON EMPTY
{ [Dimension1].[Dimension1].[Dimension1].ALLMEMBERS*
[Dimension2].[Dimension2].[Dimension2].ALLMEMBERS*
[Dimension3].[Dimension3].[Dimension3].ALLMEMBERS*
{[Date].[Date].&[2014-06-13T00:00:00], [Date].[Date].&[2014-06-16T00:00:00] }
} ON ROWS
FROM [Cube]
Furthermore, I am not sure why you added the SCOPE([Date].[Date].MEMEBER); (probably Date].[Date].MEMBERS, actually). Maybe it helps to omit it and the corresponding END SCOPE.

Display property of member in mdx query

I have a Mondrian/MDX query where I grab data within a date range, but I'd like to return time as the value of its property in the result. My current query is like:
With
set [*TIME_RANGE] as '{[Time].[2011].[3].[9].[1].[1].Lag(30):[Time].[2011].[3].[9].[1].[1]}'
set [*PXMD] as '[meta_pixel_id1.Pixel].[label].Members'
set [*BASE_MEMBERS] as 'NonEmptyCrossJoin([*TIME_RANGE],[*PXMD])'
Select
{[Measures].[total_users],[Measures].[total_action_pixels]} on columns,
[*BASE_MEMBERS] on rows
From [ActionPixels]
Where [Pixel ID].[500]
Which returns a result like:
Axis #0:
{[Pixel ID].[500]}
Axis #1:
{[Measures].[total_users]}
{[Measures].[total_action_pixels]}
Axis #2:
{[Time].[2011].[3].[8].[4].[24], [meta_pixel_id1.Pixel].[500].[Action].[Type].[Handraiser]}
{[Time].[2011].[3].[8].[4].[24], [meta_pixel_id1.Pixel].[500].[Action].[Type].[Lead]}
{[Time].[2011].[3].[8].[4].[24], [meta_pixel_id1.Pixel].[500].[Action].[Type].[Shopper]}
Row #0: 3
Row #0: 3
Row #1: 4
Row #1: 4
Row #2: 2
Row #2: 2
Which is what I expect. Problem is, I'm writing this query for use in a Pentaho xaction, so I have some Javascript code afterwards that converts this into a JSON format and when I got to extract the value of the [Time] column, I get back only the day number (in this case, 24). What I want to display instead is the property of the [Time].[Day] dimension we call Date String that contains the date formatted as year-month-day. But none of the examples I can find of how to do this will work with my selection on [Time] by range.
The most immediate solution seems to be to display the Date String property, but I'd be willing to entertain other ideas that will let me get both the data I want and filter on the time range I want.
I was able to solve the problem based on the code found online. I had tried something like that before, but it wasn't working because of what was ultimately a problem with the property in the cube that caused it to always return null rather than the value in the table the time dimension was created from.