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.
Related
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.
I read a zilion of links on this matter, but the more I read the more I'm confused.
In my DB I have a date column, with 'YYYY-MM-DD' format. I need to count the occorrences of month+year change, regardless of days. I currently use:
$query = "SELECT COUNT(data) as visits, COUNT(DISTINCT data) as diffentDates ,MIN(data) as 'MIN', MAX(data) as 'MAX' FROM visiting ";
Where 'data' is the value in my column.
This works fine: I get the totals for visits, the number of different dates, the first and the last visit.
The problem comes with 'diffentDates'; it should only count the changes in 'YYMM'.
I tried to use something similar to: COUNT( DISTINCT ( FORMAT (data,'YYMM') ) ) as diffentDates
but it does not do what I need (actually it gives errors or selects all the dates anyway).
Which is is the correct function to apply to translate (and select and count) from 'YYYY-MM-DD' to 'YYMM' ?
Thanks
If the column data is a TIMESTAMP or DATE type, the following should work:
SELECT
COUNT(`data`) as visits,
COUNT(DISTINCT DATE_FORMAT(`data`,'%Y%m')) as diffentDates,
MIN(`data`) as 'MIN',
MAX(`data`) as 'MAX'
FROM `visiting`
#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.
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)
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')...}"