SpagoBI OLAP report passing optional parameter - reporting-services

Helo. Today is my another fight day with OLAP raport with optional parameter. I have problem with MDX query. I wrote it like this:
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF(ISEMPTY([CUSTOMER].[${param}]) //CHECKING IF PARAMETER IS EMPTY
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[${param}]}
)
}ON ROWS
from [TRANSACTIONS]
${param} is my optional parameter for [CUSTOMER].[COUNTRY]. I unchecked "required" check button for my parameter, so OLAP should have all [VALUE] after executing it without parameter. And there is a problem, because after launching my OLAP raport parameter probably wants to be filled with something. It gives me an error.
Profile attribute 'param' not existing.
But I dont want to fill it with profile attribute. I have created list of values, and analytical driver for my parameter, which I use to pass possible values to my list box string parameter - ${param}.
Is there possibility to have OLAP report with optional parameter? Any BI master here?
I would be greatfull for any help.
Update: I have done something like this, I think this syntax is right, (I was checking SpagoBI examples)
WITH MEMBER [CUSTOMER].[SELECTED] AS ' Parameter("param") ' , SOLVE_ORDER = 2
MEMBER [CUSTOMER].[LEN] AS ' LEN(Parameter("param")) ', SOLVE_ORDER = 1
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF([CUSTOMER].[LEN]=0
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[CUSTOMER].[SELECTED]}
)
}ON ROWS
from [TRANSACTIONS]
But now I have same error for both possibilities (set/unset) parameter
javax.servlet.jsp.JspException: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: com.tonbeller.jpivot.olap.model.OlapException: 1
Any ideas? Thanks :)

This question is a direct copy oF your previous posts:
https://stackoverflow.com/questions/38970610/olap-report-with-optional-parameter
Is ${param} is a string?
If it is a string then the following should function:
WITH MEMBER [Measures].[x] AS ${param}
SELECT
NON EMPTY {[Measures].[x]} ON COLUMNS
FROM [TRANSACTIONS];
Does it function?
If it does not function then the question is not really mdx related - as for some reason your syntax or the way the parameter is moving to the client is wrong.
note
The above is the equivalent of this super simple script:
WITH
MEMBER [Measures].[x] AS "hello world"
SELECT
NON EMPTY
{[Measures].[x]} ON 0
FROM [Adventure Works];
Do you have AdvWrks cube? Try these:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(IsEmpty([Measures].[x])) //<< this returns False
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< this is what IIF returns
)
} ON 0
FROM [Adventure Works];
It returns this:
Now I tested out IsEmpty:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(NOT //<< added this to check functionality of IsEmpty
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS //<< this is what IIF returns
,{[Measures].[x]}
)
} ON 0
FROM [Adventure Works];
We get the following:
What I think is happening in your scenario is this - the param is not empty but is actually a zero length string:
WITH
MEMBER [Measures].[x] AS ""
SELECT
{
IIF
(
(
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< the zero length string goes to here
)
} ON 0
FROM [Adventure Works];
Results in:

Related

Index was outside the bounds of the array in SSRS

I have two parameters , let's say P1 and P2. The sample expression I used for P2 is
IIF(P1.Label="string", "null" ,Split(P1.Label," ").GetValue(0))
When the condition is false, the split expression is working fine. But if the condition is true, I'm getting 'Index was outside the bounds of the array' error. If the condition is true, I need to pass the value "null" as varchar type.
Can someone please advice on this?
The problem with the IIF function is that it is a function not a language construct. This means that it evaluates both parameters before passing the parameters to the function. Consequently, if you are trying to do a Split on a parameter that can't be split, you will still get the 'Index was outside the bounds of the array' error, even when it looks like that code shouldn't be executed due to boolean condition of the IIF statement.
The best way to solve this is to create a safe string splitter function in custom code where you can use real language constructs. Also, check that the string is splittable by checking it contains a space instead of checking for a special string:
Public Function SafeSplit(ByVal SplitThis As String) As String
If InStr(SplitThis, " ") Then
Return Split(SplitThis, " ")(0)
End If
Return "null"
End Function
and then use this in your report for the Value expression instead of IIF:
=Code.SafeSplit(Parameters!P1.Label)

SUM IIF Expression returning an error

I have a simple expression that should work,but it keeps returning an error.
Please keep in mind, the Parameter is a Multi elect Parameter.
=SUM(IIF(Fields!Month.Value = Month(Today()) AND Fields!Year.Value = Year(Today()) AND Fields!Warehouse.Value = Parameters!warehouse.Value, Fields!Budget.Value, 0), "Budgets")
Since the parameter is multi-value, the values are passed as an array. One way to handle this is by combining the values into a comma-separated string.
So you would replace Fields!Warehouse.Value = Parameters!warehouse.Value with:
InStr(Join(Parameters!warehouse.Value, ","), Fields!Warehouse.Value) > 0

Hiding table or assigning temp data based on visibility expression ssrs 2008

I have a table in ssrs 2008. This table has a row visibility expression like:
=IIF(max(Fields!VExpected.Value) <> "", 1, 0) +
IIF(max(Fields!MExpected.Value) <> "", 1, 0) +
IIF(max(Fields!PExpected.Value) <> "", 1, 0) = 3, false, true)
Sometimes the datasource returns no data, or the returned data is not matching with this expression. In this case what I see is that a table with borders and column names but no data on it like:
id Vex Mex Pex
However, I want to show it as
id Vex Mex Pex
- - - -
Or if possible:
id Vex Mex Pex
No Data
Another question is, is there any way to hide the complete table if there is no returning data or any matching data with the expression?
Thanks
You can use CountRows function to determine how many rows your dataset is returning. If it is zero hide the table otherwise show it.
=iif(CountRows("DataSetName")=0,true,false)
Replace DataSetName by the actual name of your dataset.
For not matching expression data you can use the this expression.
=IIF(
max(Fields!VExpected.Value) <> "" AND
max(Fields!MExpected.Value) <> "" AND
max(Fields!PExpected.Value) <> "",False,True
)
The whole expression for matching expression and no rows cases could be something like this:
=Switch(
CountRows("DataSetName")=0,true,
max(Fields!VExpected.Value) = "",true,
max(Fields!MExpected.Value) = "",true,
max(Fields!PExpected.Value) = "",True,
true,False
)
Supposing VM, ME and PE expected values are numeric type I'd use ISNOTHING() function to determine when null values are being returned.
=Switch(
CountRows("DataSetName")=0,true,
ISNOTHING(max(Fields!VExpected.Value)),true,
ISNOTHING(max(Fields!MExpected.Value)),true,
ISNOTHING(max(Fields!PExpected.Value)),True,
true,False
)
Additional you can set a message when no rows are being returned from your dataset. Select the tablix and press F4 to see properties window. Go to NoRowsMessage property and use an expression to say your users there is no data.
="There is no data."
In this cases the tablix will not appear in your report but the message you set will be rendered in the location where the tablix should be.
Let me know if this helps.

SSRS Space Issue in Parameter Value

I am facing some issues with parameter in SSRS reports that when my Multi value parameter contains the space in between then I get the syntax error
If i choose any other parameter value which do not contains the space then it works well. I am using SSAS cube as a data source
WITH MEMBER [Measures].[PV] AS #Percentile
Member [Measures].[CntCT] as Count(NonEmpty(STRTOSET(#State) * [Tb Main].[UID].[UID].ALLMEMBERS,[Measures].[CPT1] ))
Member [Measures].[PVInt20] as Int(((([Measures].[CntCT] - 1)* [Measures].[PV])/100) - 1)
Member [Measures].[PVC] as
([Measures].[CPT1],Order(NonEmpty(STRTOSET(#State)*[Tb Main].[UID].[UID].ALLMEMBERS ,
[Measures].[CPT1]), [Measures].[CPT1],BASC).Item([Measures].[PVInt20]))
Select [Measures].[PVC] on columns, STRTOSET(#State) on rows from [POC 1];
Query works in query designer with both parameter and entire unique name i.e [Tb Main].[State Name].&[Wash DC]
Try changing the state parameter query to:
WITH
MEMBER [Measures].[ParamValue] as [Tb Main].[State Name].CurrentMember.UniqueName
SELECT { [Measures].[ParamValue] } ON COLUMNS,
NonEmpty ([Tb Main].[State Name].[State Name].ALLMEMBERS, [Measures].[CPT1] ) DIMENSION PROPERTIES MEMBER_CAPTION ON ROWS FROM [POC 1]
Use the ParamValue column as the value property of the state parameter. Then your query downstream should work even when there are spaces.

Parameter returns error because it was referenced in an inner subexpression

I've created a simple query in MDX to lookup a value. When i use this it works:
With
MEMBER [Measures].[dummy] as 1
select non empty {
[Measures].[dummy]
} on columns,
non empty {
except([Product].[Code].members, [Product].[Code].[All])
* except([Product].[Description].members, [Product].[Description].[All])
} on Rows
FROM
(SELECT Filter([Product].[Description].[Description].Members,
(InStr(1,[Product].[Description].CurrentMember.member_caption,"502080")>0))
ON COLUMNS
FROM [Cube])
but when i try to make this dynamic for use with MSRS it gives me an error:
"The SearchFor parameter could not be resolved because it was referenced in an inner subexpression"
This is my code with parameter:
With
MEMBER [Measures].[dummy] as 1
select non empty {
[Measures].[dummy]
} on columns,
non empty {
except([Product].[Code].members, [Product].[Code].[All])
* except([Product].[Description].members, [Product].[Description].[All])
} on Rows
FROM (
SELECT StrToMember
("Filter([Product].[Description].[Description].Members,
(InStr(1,[Product].[Description].CurrentMember.member_caption," + StrToMember(#SearchFor) + ")>0))")
on Columns
FROM [Cube])
Who knows how to get around this error? Please point me into the right direction.
Thanks in advance.
The way in which you use the parameter is as a simple string, not as a member reference. Hence, just leave away the StrToMember so that the FROM clause gets
FROM
(SELECT Filter([Product].[Description].[Description].Members,
(InStr(1,[Product].[Description].CurrentMember.member_caption, #SearchFor)>0))
ON COLUMNS
FROM [Cube])
It is difficult to check this without access to your cube.
However, to check the logic of the expression, you could issue a query like this:
WITH MEMBER Measures.[test0] as
#SearchFor
MEMBER Measures.[test1] as
InStr(1,[Product].[Description].CurrentMember.member_caption, #SearchFor) > 0
SELECT { Measures.[test0], Measures.[test1] } on columns,
{
[Product].[Description].[ABC],
[Product].[Description].[DEF],
[Product].[Description].[GHI],
[Product].[Description].[JKL]
} on rows
FROM [Cube]
You should replace the product list with some products really existing in your cube, some which fulfill the search criteria, and some that do not. Then you should be able to see True and False in the last column, depending if the match with the search criteria is successful or not. And the column to the left of it should display your search parameter in all rows.
It turned out my report would not show the data i retrieved with my MDX query. I started over with a new dataset:
With
MEMBER [Measures].[ParameterCaption] AS [Product].[Description].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS [Product].[Description].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS [Product].[Description].CURRENTMEMBER.LEVEL.ORDINAL
select {
[Measures].[ParameterCaption], [Measures].[ParameterValue], [Measures].[ParameterLevel]
} on columns,
EXCEPT([Product].[Description].MEMBERS,[Product].[Description].[All]) *
EXCEPT([Product].[Code].MEMBERS,[Product].[Code].[All])
ON ROWS
FROM ( SELECT FILTER ([Product].[Description].Members,
(InStr ([Product].[Description].CurrentMember.Name,
#SearchFor) <> 0)) ON COLUMNS FROM [Cube])
After adding a new tablix in my report the filter works as expexted. I still have no idea why my previous MDX wasn't working with the report.