SimeReplacing WeekOfYear Dynamically - mdx

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

Related

How to insert a string literal as a new column in an mdx query

In the following MDX query, I want to set the value of [Measures].[Label] as the string literal "Net Value" instead of NULL (i.e. using a string literal to populate the values in the label column). I'm scratching my head about how to do this in MDX. Tons of background with SQL, but a relative newbie with SSAS.
`WITH
Member [Measures].[Label] AS NULL
Member [Measures].[Value] AS [Measures].[Net Amt]
SELECT NON EMPTY
(
{[Time].[Quarter].[Quarter]},
{[Time].[Month].[Month]},
{[Time].[Work Week].[Work Week]},
{[Customer].[Region Cd].[Region Cd]},
{[Product].[Cd Nm].[Cd Nm]}
) ON Rows,
NON EMPTY
(
{
[Measures].[Value],
[Measures].[Label]
}
) ON Columns
FROM [Reporting]
WHERE
(
{
[Time].[Year].[Year].&[2022]:[Time].[Year].[Year].&[2023]
},
{[Segment].[Segment Nm].[Segment Nm].&[SEG VALUE]}
)`
If I try a value in double quotes, the query just times out without finishing. Just using a null like this only takes 2 seconds to return.
Member [Measures].[Label] AS "Net Amt"
The problem with putting a constant is that the NON EMPTY now returns every combination of Time, Customer and Product.
Instead you want to return a constant but only on rows where the Net Amt measure is not empty.
Member [Measures].[Label] AS IIF(Not(IsEmpty([Measures].[Net Amt])),"Net Amt",Null)
Alternately you could use a constant but use the NonEmpty function instead against the Net Amt measure only:
Member [Measures].[Label] AS "Net Amt"
Member [Measures].[Value] AS [Measures].[Net Amt]
SELECT NonEmpty(
{
{[Time].[Quarter].[Quarter]}*
{[Time].[Month].[Month]}*
{[Time].[Work Week].[Work Week]}*
{[Customer].[Region Cd].[Region Cd]}*
{[Product].[Cd Nm].[Cd Nm]}
},
[Measures].[Net Amt]
) ON Rows,
{
[Measures].[Value],
[Measures].[Label]
}
ON Columns

Return data between two dates from a MDX Query SSAS

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

SQL to MDX conversion

I have this where clause in sql language:
where (cond1=1 or cond2=1) and cond3=1
How can I get this result in MDX with the slicing(condition into the where)?
{[cond1].&[1],[cond2].&[1]} /*and*/ {[cond3].&[1]}
Thanks
Try to use a subcube:
Select
-- YOUR SELECTED MEASURES AND DIMENSIONS
From
(
Select
{[cond1].&[1],[cond2].&[1]} on 0
,{[cond3].&[1]} on 1
-- ,{more slices} on x
From [CubeName]
)
Hope this help!
You can use subcube expression as stated above, but this is not the only option. If you use subcube, you would increase query performance greatly (assuming the fact you don't perform crossjoins in it).
You can also use general WHERE keyword after last expression that returns cube:
select
{ .. } on 0,
{ .. } on 1
from (select { [Dim1].[X].allmembers } on 0)
where ([Dim2].[Y].&[Y1])
Or:
select
{ .. } on 0,
{ .. } on 1
from (select { [Dim1].[X].allmembers } on 0)
where {[DimTime].[Time].[Year].&[2001] : [DimTime].[Time].[Year].&[2015]}
This is applied at the end of execution, which means performance may decrease. However, if you need to apply external filter to all axis, this is the option you need.
Another way to filter member values is using tuple expressions:
with member LastDateSale as ( (Tail(EXISTING [DimTime].[Time].[Dates].members,1), [Measures].[ActualSales]) )
This will take your DimTime axis, apply external filter, get the last element from it and calculate [ActualSales] for it, if possible.

MDX SORTING not Working

I want to sort one column in the desending format.The MDX query need to sort out is shown below.In der I am using the "[Measures].[Count]" field in the where clause.And i want to sort the measures in descending format..I already used the "ORDER" Function in the qry.bt i am getting errors..
/*
SELECT
NON EMPTY { [Operator].[Total],[Operator].[Total] .Children } ON COLUMNS,
NON EMPTY { [Circle].[Total], [Circle].[Total] .Children } ON ROWS FROM
[GENERATOR]
WHERE
( [Measures].[Count], [RoamingFlag].[INRoaming], [Date].[${yesterday}] , [SuccessFailureDetails].[FAILURE] )
*/
Can anyone help me to solve the problem..
Thanks...
SELECT
NON EMPTY {[Operator].[Total],[Operator].[Total].Children} ON COLUMNS,
NON EMPTY ORDER({[Circle].[Total],[Circle].[Total].Children},[Measures].[Count],BASC) ON ROWS FROM [GENERATOR]
WHERE
([Measures].[Count], [RoamingFlag].[INRoaming], [Date].[${yesterday}],[SuccessFailureDetails].[FAILURE])
Hopefully!

MDX " BETWEEN .. AND" CONDITION

I am using one MDX Equation as shown below.
SELECT
NON EMPTY { [Operator].[Total],[Operator].[Total] .Children } ON COLUMNS,
NON EMPTY { [Circle].[Total], [Circle].[Total] .Children } ON ROWS FROM
[16CircleWiseRoamingFailure5]
WHERE
( [Measures].[Count], [RoamingFlag].[INRoaming], [Date].[${yesterday}] , [SuccessFailureDetails].[FAILURE] )
here i am passing one function called "yesterday" which gives only yesterdays data.
Now i want to find values within an interval e.g. between month or between days. Can anyone tell me the syntax...?
In Analysis Services, you can use a range, using the ":" operator.
http://msdn.microsoft.com/en-us/library/ms146001.aspx
Don't know if it works in Pentaho