Return data between two dates from a MDX Query SSAS - sql

I'm trying to filter data between two date ranges. Its data type is datetime.
I have generated the query via the Query designer in SSAS.
Below is sample of the dataset I have:
Sample image of Measure groups and dimensions:
Sample Filter I have used:
Generated MDX Query:
`SELECT NON EMPTY { [Measures].[Status] } ON COLUMNS, NON EMPTY { ([Lobby].[Added Local Time].[Added Local Time].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( [Lobby].[Added Local Time].&[2020-01-02T10:32:37.806667] : [Lobby].[Added Local Time].&[2020-02-19T13:43:13.833333] ) ON COLUMNS FROM ( SELECT ( { [Lobby].[Status].[All] } ) ON COLUMNS FROM [LTS KROI DEMO])) WHERE ( [Lobby].[Status].[All] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS`
Problem:
Issue is that it doesn't filter the data according to the given datetime ranges. Neither gives any error.
If I use the only the Filter - Status a specific value without giving all it all works fine.

Please try the Filter function. It will be slower but should work since the approach you took only works if the exact date time exists
SELECT { [Measures].[Status] } ON COLUMNS, NON EMPTY {
Filter(
[Lobby].[Added Local Time].[Added Local Time].ALLMEMBERS,
[Lobby].[Added Local Time].CurrentMember.MemberValue >= CDate("2020-01-02 10:32:37.806667")
and [Lobby].[Added Local Time].CurrentMember.MemberValue <= CDate("2020-02-19 13:43:13.833333")
)
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS
FROM [LTS KROI DEMO]
CELL PROPERTIES VALUE

I was able get the desired result by following the answer of
#GregGalloway by making a small change to the parameter I passed as
the date. When I removed time passing the date to the Cdate function
it work fine.
SELECT { [Measures].[Status] } ON COLUMNS, NON EMPTY {
Filter(
[Lobby].[Added Local Time].[Added Local Time].ALLMEMBERS,
[Lobby].[Added Local Time].CurrentMember.MemberValue >= CDate("2020-01-02")
and [Lobby].[Added Local Time].CurrentMember.MemberValue <= CDate("2020-02-19")
)
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_VALUE, MEMBER_UNIQUE_NAME ON ROWS
FROM [LTS KROI DEMO]
CELL PROPERTIES VALUE

Related

SimeReplacing WeekOfYear Dynamically

I am using copy activity in ADF in which i have following pseudo query:
SELECT
{
[Measures].[**************],
[Measures].[**************],
[Measures].[**************]
} ON COLUMNS,
NON EMPTY
{
[0CALWEEK].[LEVEL01].MEMBERS
}
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM cubeName/ReportName
SAP VARIABLES [SAP_VARIABLE_NAME]
INCLUDING [0CALWEEK].[201905]
In the above i want to replace '201905' dynamically,there is no current function availabe to get WeekOfYear in ADF Expressions and functions OR can i use MDX Query to generate WeekOfYear
Take a look at this example how it changes value for a member value. Please note I have answerd if from phone so some syntax issue might exist.
With member measures.t
As
Case when
[0CALWEEK].[LEVEL01]. currentmember.name="'201905"
Then 1
Else
0
End
SELECT
{
[Measures].[t]
} ON COLUMNS,
NON EMPTY
{
[0CALWEEK].[LEVEL01].MEMBERS
} ON ROWS
FROM cubeName/ReportName

MDX Function (Excel PowerPivot) to Exclude Non Numeric Values from DB

I am quite new to MDX and I am trying hard to write a query that allows me to retrieve only numeric values.
My query at present is:
SELECT NON EMPTY {ISNUMERIC([Measures].[Average Booking Window])}
ON COLUMNS, NON EMPTY {
([Stay Date].[Year].[Year].ALLMEMBERS *
[Stay Date].[Month of Year].[Month of Year].ALLMEMBERS )
} DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME
ON ROWS FROM (
SELECT ( [Booking Date].[Calendar].[Date].&[2018-01-01T00:00:00] :
[Booking Date].[Calendar].[Date].&[2018-08-31T00:00:00] )
ON COLUMNS FROM (
SELECT ( { [Hotel].[Market].&[Pisa City, Italy] } )
ON COLUMNS
FROM [MYCUBE]))
WHERE ( [Hotel].[Market].&[Pisa City, Italy])
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR,
FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE,
FONT_FLAGS
The error I get is:
Query (1, 18) The function expects a tuple set expression for the 1 argument. A string or numeric expression was used.
What I am expecting is to get data only when it's numeric and I want the MDX query to completely exclude the rows with non numeric data.
Thank you in advance

MDX SET within Measures axis

In MDX, is it possible create a Named Sets when including with the Measures Axis eg
WITH
SET [MyFields] AS (
IIF((IsEmpty([Measures].[MeasureField])), null,
IIF(([School].[Key].CurrentMember IS [School].[Key].&[9999] or [School].[Key].CurrentMember IS [School].[Key].&[8888])
,{[Measures].[MeasureField]}
,IIF(([Semester].[Key].CurrentMember IS [Semester].[Key].&[1])
,{[Measures].[MeasureField]}
,null
)
)
)
)
SET [MyNonEmpty] AS (
NonEmpty(
{([Student].[UniqueId].[UniqueId].members,({ [School].[Key].&[9999], [School].[Key].&[8888] })
)
)
SELECT {
MyFields
} ON COLUMNS
,NON EMPTY { (
MyNonEmpty
* [Dim1].[Field1].[Field1].ALLMEMBERS
* [Dim2].[Field2].[Field2].ALLMEMBERS
...
}
...
Although I can use a Calculated Member on the Dimensions (COLUMNS above) axis (and successfully return rows), the above syntax which uses the Named SET in the Measures (ROWS) axis, returns no rows (and no error).
Just a note - in the the above example no rows are returned regardless of whether MyFields is empty or non-empty

Get Current Date in MDX Query

I am trying to get current date records and I have a query where a particular date is given , how can I put currentdate in that position.
I am new to MDX, if anyone answer that will be really helpful.
Below is the MDX query :
SELECT NON EMPTY { [Measures].[SHC] } ON COLUMNS, NON EMPTY { ([C].[RHC].[rhc].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( { [DHC].[DHC].&[01/01/1992] } ) ON COLUMNS FROM [TABULAR_EAL]) WHERE ( [DHC].[DHC].&[01/01/1992] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
I want to get records based on CurrentDate.
Something like this:
StrToMember('[DHC].[DHC].&[' + Format(Now(),'dd/MM/yyyy') + ']')
See my blogpost for more details.
I complete the answer :
With Member Measures.CurrentDate As
Format(
Now(),
'yyyyMMdd'
)
Member Measures.GetMemberCurrentDate as
'[Start Date].[Miladi Int Date].&['+ measures.CurrentDate + ']'
member Measures.GetCurrentDateBimehValue as
(StrToMember(Measures.GetMemberCurrentDate) ,[Measures].[BimehValue])
select Measures.GetCurrentDateBimehValue on columns
from [BimehCube]

CDE: multiple select

I am trying to create a dashboard that consist from two components: CCC Bar chart and Multiple select component.
I use the multiply select component for assignment param value, which is using in the datasource. (MDX query):
SELECT
NON EMPTY {[Measures].[doc_count]} ON COLUMNS,
NON EMPTY {[Dimension Usage date_publish.Hierarchy date_publish].[date_publish].Members} ON ROWS
FROM [Docs]
WHERE CrossJoin({${param_hosts}}, {[event].[active]})
So if I set (multiply select component) property value array with pairs:
( {arg:[host].[news.com] value:news.com}, {{arg:[host].[somesite.com] value:somesite.com}} ), everything work perfect.
The parameter is bound to the component receives the correct value, for example: [host]. [News.com], [host]. [Somesite.com].
But if I try to fill the multiply select component from the datasource it become unworkable.
As DataSource, I use the sql over sqlJndi with query: SELECT distinct (host) as Id, concat ('[host]. [', Host, ']') as Value FROM docs_fact where dim_event_id = 1;
The result this query is a table:
id value
news.com | [host].[news.com]
somesite.com | [host].[somesite.com]
Parameter is assigned a value: news.com, somesite.com
Changing the properties of the Value as id only affects which of the fields (id or value) will be shown to the user, and the parameter's value is not affected.
Tell me please, is it possible to specify which of the columns to be used for display to the user and which of the columns to be used to generate results?
No, but you can change the dataset on the clientside using the postFetch function on the multi-select component.
function (dataset) {
for (var i=0; i < dataset.resultset.length; i++) {
var temp = dataset.resultset[i][0];
dataset.resultset[i][0] = dataset.resultset[i][1];
dataset.resultset[i][1] = temp;
}
return dataset;
}
Or similar