MDX Query Error on SSRS Report - reporting-services

Function expects a tuple set expression for the first argument. A string or numeric expression was used.
I am designing the mdx query on my ssrs report.
Here is my MDX query:
SELECT
NON EMPTY { [Measures].[Order Quantity], [Measures].[Discount Amount], [Measures].[Freight], [Measures].[Extended Amount] } ON COLUMNS,
NON EMPTY { ([Customer].[Customer Key].[Customer Key].ALLMEMBERS * [Currency].[Currency Key].[Currency Key].ALLMEMBERS * [Currency].[Currency Name].[Currency Name].ALLMEMBERS * [Customer].[Gender].[Gender].ALLMEMBERS ) } ON ROWS
FROM (
SELECT ( STRTOSET ( '{" & Join(Parameters!CurrencyCurrencyKey.Value,",") & "}') ) ON COLUMNS
FROM [AWDW]
)
Any Idea?????

I think the call to Join does not return a correct expression. To make your query works, it should return something like the unique name of a Currency Key.
I do not know if you want to select 1 or several currency but the first argument of StrToSet must have a value like:
"{'unique name of the currency'}"
or
"{('unique name of the first currency') , ('unique name of the second currency')...}"

Related

MDX StrToMember date range issues

It seems like the query can't get date range to work. I'm passing two dates as a parameters and based on that I would expect to have [Sector Name] dropdown values retrieved based on the date range(#FromJoinDateDate:#ToJoinDateDate) and both #ADMTRANSINSpecialty and #ADMTRANSINSite which last two seems to be working properly.
Example of parameters:
#FromJoinDateDate: [Sector_Join_Date].[Date].&[2020-07-29T00:00:00]
#ToJoinDateDate: [Sector_Join_Date].[Date].&[2021-07-29T00:00:00]
WITH
MEMBER [Measures].[ParameterCaption] AS [ADM_TRANS_IN].[Sector Name].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS [ADM_TRANS_IN].[Sector Name].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS [ADM_TRANS_IN].[Sector Name].CURRENTMEMBER.LEVEL.ORDINAL
SELECT {
[Measures].[ParameterCaption],
[Measures].[ParameterValue],
[Measures].[ParameterLevel]
} ON COLUMNS ,
[ADM_TRANS_IN].[Sector Name].ALLMEMBERS ON ROWS
FROM ( SELECT ( STRTOSET(#ADMTRANSINSpecialty, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT ( STRTOSET(#ADMTRANSINSite, CONSTRAINED) ) ON COLUMNS
FROM ( SELECT { STRTOMEMBER(#FromJoinDateDate, CONSTRAINED) :
STRTOMEMBER(#ToJoinDateDate, CONSTRAINED) } ON COLUMNS
FROM [Model])))
I have a feeling that StrToMember function might be returning null in both cases which is why the results are not matching the query, however I need to use it in order to use range function. Could it be also the date format not matching what is in the cube?
One way to check the actual date format value in your Date dimension is as follows:
Create a new query
Navigate to your date dimension, expand members, select a date and drag and drop to your query window.
This will then show you the exact date format for your data.
An example screen shot using the AdventureWorks sample is given below:
As can be seen, even though in the tree it is shown as "January 1, 2005", the actual data is of the format: 20050101.
Once you able to find the actual date format in your data, you can then constuct the string representation accordingly.

SSRS: How can i use a Parameter in MDX Query?

I have been trying for some time to get a Parameter to work within an MDX Query which is automatically generated by SSRS Query Designer.
I have tries the following:
FROM ( SELECT ( {[Dim Date].[Fiscal Year].&[+"#Current_FYear"+]}) ON COLUMNS
FROM ( SELECT ( { [Dim Date].[Fiscal Year].[+"#Current_FYear"+} ) ON COLUMNS
FROM ( SELECT ( {StrToMember(#Current_FYear,CONSTRAINED).lag(23):StrToMember(#Current_FYear, CONSTRAINED)}) ON COLUMNS
FROM ( SELECT ( {[Dim Date].[Fiscal Year].[+"Parameters!Current_FYear.Value"+]}) ON COLUMNS
And none of the above give me the result i am looking for: To have the Dataset filter by the value in the Parameter.
Any help on this would b emuch appreciated!
Thanks,
First of all, I would suggest using the Parameter checkbox in the Query Designer and let SSRS build the MDX for you. Here's a screenshot in case you missed it.
Another reason to let the report create the parameter for you is that it will automatically create another hidden Dataset to populate the available values of the parameter.
If you do want to edit the MDX manually, the syntax could look like this:
SELECT NON EMPTY { [Measures].[Measure] } ON COLUMNS FROM (
SELECT ( STRTOSET(#Parameter, CONSTRAINED) ) ON COLUMNS FROM [Model])
The STRTOSET function converts the parameter value into MDX syntax. It can also handle multi-value parameters.
The parameter you reference here would also need to be defined in the Parameters tab of the Dataset Properties. This is where you link the parameter value from the report to the query.

MySQL Return the first non-NULL value from the list of the column in select statement with column name

I have a sql query below:
SELECT
md.refereeInternetSearch,
md.refereeCompanyColleague,
md.refereeIndustryPeer,
md.refereeIndustryEvent,
md.refereeIndustryPublication,
md.refereeMarketingEmail,
md.refereeOther
FROM
marketing_details md
WHERE
md.id = 14588
From the 7 columns in the above select statement only one column will have a value and rest will be null. Is it possible to select just that one column value that is not null using some sort of sql statement ?
Use the coalesce() function to return the 1st non-null value from a list of parameters:
SELECT
coalesce(md.refereeInternetSearch,
md.refereeCompanyColleague,
md.refereeIndustryPeer,
md.refereeIndustryEvent,
md.refereeIndustryPublication,
md.refereeMarketingEmail,
md.refereeOther) as non_null_value
FROM
marketing_details md
WHERE
md.id = 14588
However, it will not be able to tell you which column the value came from.
UPDATE
If you really want to use sql to retrieve the name of the field that has the non null value, then you can do that with the following monstrous sql statement below. What it does it concatenates each field value from a record into a single string, where the values are separated by comma. NULL values are converted to empty string. Then using find_in_set() function it finds the position of the only non null value within the above string. Then using the elt() function it returns the name of the field from the list of field name literals based on the position returned by find_in_set().
SELECT
md.id,
coalesce(md.refereeInternetSearch,
md.refereeCompanyColleague,
md.refereeIndustryPeer,
md.refereeIndustryEvent,
md.refereeIndustryPublication,
md.refereeMarketingEmail,
md.refereeOther) as non_null_value,
elt(find_in_set(coalesce(md.refereeInternetSearch,
md.refereeCompanyColleague,
md.refereeIndustryPeer,
md.refereeIndustryEvent,
md.refereeIndustryPublication,
md.refereeMarketingEmail,
md.refereeOther),
concat(coalesce(md.refereeInternetSearch,''),',',
coalesce(md.refereeCompanyColleague,''),',',
coalesce(md.refereeIndustryPeer,''),',',
coalesce(md.refereeIndustryEvent,''),',',
coalesce(md.refereeIndustryPublication,''),',',
coalesce(md.refereeMarketingEmail,''),',',
coalesce(md.refereeOther,'')
)
),'refereeInternetSearch',
'refereeCompanyColleague',
'refereeIndustryPeer',
'refereeIndustryEvent',
'refereeIndustryPublication',
'refereeMarketingEmail',
'refereeOther'
) as field_name
FROM
marketing_details md
WHERE
md.id = 14588
Huh, I hope I got all the parentheses right!

How to pass apply ssrs parameters on multiple dimension attributes

#StartDate and #EndDate parameters must added to the MDX query for usage in SSRS data set. strtomember can be used like this:
SELECT (
strtomember(#StartDate) : strtomember(#EndDate)
) ON COLUMNS FROM [Cube]
How can I specify that sub-select must work on the [Fact A] and [Fact B] rundate? strtomember(#StartDate) does not specify on which attribute this sub select is going to work. Any pointers?
FROM
(
SELECT
(
[Fact B].[Rundate].&[2015-01-02T00:00:00] : [Fact B].[Rundate].&[2015-01-15T00:00:00]
) ON COLUMNS FROM
(
SELECT
( [Fact A].[Rundate].&[2015-01-02T00:00:00] : [Fact B].[Rundate].&[2015-01-15T00:00:00] ) ON COLUMNS FROM [Cube]
)
)
I know nothing about your requeriments but assuming Fact A and Fact B have different Rundate members I think you should create a #StartDate and #EndDate for every Fact you want to filter.
Also you can have an additional parameter to select the Fact Table, once the Fact Table is selected you can populate date parameters.
If you don't have a Time Dimension related to Fact tables you have to populate parameters from Facts.

SSAS (MDX) - Filtering Dataset based on another Dataset

I have a mdx report on a cube. As available values for division number report parameter I have an autogenerated dataset (dataset1, with all divisions in company) which query looks like this:
WITH MEMBER [Measures].[ParameterCaption] AS
[Dim Division].[Hierarchy].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS
[Dim Division].[Hierarchy].CURRENTMEMBER.UNIQUENAME
MEMBER [Measures].[ParameterLevel] AS
[Dim Division].[Hierarchy].CURRENTMEMBER.LEVEL.ORDINAL
SELECT {[Measures].[ParameterCaption], [Measures].[ParameterValue], [Measures].[ParameterLevel]}
ON COLUMNS ,
[Dim Division].[Hierarchy].ALLMEMBERS
ON ROWS
FROM ( SELECT ( STRTOMEMBER(#FromDimDateHierarchy, CONSTRAINED) : STRTOMEMBER(#ToDimDateHierarchy, CONSTRAINED) )
ON COLUMNS
FROM [ArveCubeBiceps]
)
I have another dataset (dataset2), which consists of only those division numbers, which logged in user is supposed to be able to view (data supplied by a procedure). I need to filter dataset1 available values by the values of dataset2.
-I can't just use the dataset2 as available values for division number, since report query is MDX, and expects tuples, which dataset2 doesn't provide. When I try to concatenate dataset2 values into tuples, I get an error that I can`t use "&" for Object() type.
-When I create a hidden parameter on report, which available and default values are those from dataset2, and then apply a filter expression to dataset1 query, which says "DivisionID in #hidden_parameter" - I get no available values for the Division parameter ( I checked the tables, all data is there )
What do I have to do to get this filter expression working... please help anyone :)
#mmarie
second dataset is created by stored procedure:
USE [Biceps]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ArveDivisionsByUserID]
#ldapuid nvarchar(30)
AS
BEGIN
declare #hier as hierarchyid
declare #managerID as int
select #managerID = em.employeeID from Dim_Employee2 em where em.ldapuid = #ldapuid
select #hier = dv.hier from Dim_Division dv where dv.managerID = #managerID and hier is not null order by hier desc
select divisionID from Dim_Division dv where hier.IsDescendantOf(#hier)=1 order by hier
END
#FrankPI - offtopic
don't know why, but I used ctrl+k for code, but it`s still regular text :(
If you can change the second query, then this could return the list of allowed members as a set definition string instead of a list of members, using e. g. the SetToStr function. This could then be used in the first query as a parameter replacing the text [Dim Division].[Hierarchy].ALLMEMBERS for the rows by StrToSet(#AllowedDivisionSet, CONSTRAINED).
If the result sets are not huge, the easy way is to do this is with a filter on the Dataset and NOT in MDX:
Add a Boolean filter in which the Expression is =True and the Value is something like this:
=iif(instr(join(Parameters!DataSet2Parameter.Value,","),
Fields!ToDimDateHierarchy.Value)=0,True, False)