I have the following MDX Query:
SELECT { [Measures].[Work Order Count Housekeeping Per Sq Ft],
[Measures].[Work Order Count],
[Measures].[House Keeping Square Footage]} ON 0,
{ ( [Location].[Entity Location Name].Members ) } ON 1
FROM [Work Order]
WHERE ( { [Department].[Department Name].[Housekeeping]},
{ [Location].[Entity Location ID].[12280], [Location].[Entity Location ID].[14067], [Location].[Entity Location ID].[15092]},
{ [Event Start Dates].[Date Key].[20160705] : [Event Start Dates].[Date Key].[20180705] },
{ [Owner Entity].[Entity ID].[12279], [Owner Entity].[Entity ID].[12280], [Owner Entity].[Entity ID].[14067], [Owner Entity].[Entity ID].[15092]},
{ [Work Order Days Open].[Days Open].[1] : [Work Order Days Open].[Days Open].[250] },
{ [Work Order Days Overdue].[Days Overdue].[1] : [Work Order Days Overdue].[Days Overdue].[250] } )
This is what I get as a result:
I was expecting (*and need) the All values to be 6.42857, 45 and 7 rather than the values I get.
What am I doing wrong in my query?
ALL will always be ALL
Seems like you want a new ALL that is the aggregation of the 3 members selected in the WHERE clause.
You can create an ALLcustom member using a WITH clause:
WITH
SET LocationSet AS
{ [Location].[Entity Location ID].[12280],
[Location].[Entity Location ID].[14067],
[Location].[Entity Location ID].[15092]}
MEMBER Location].[Entity Location ID].[All].ALLcustom AS
AGGREGATE ( LocationSet )
SET [Locations] AS
{LocationSet,
[Location].[Entity Location ID].[All].ALLcustom
}
SELECT { [Measures].[Work Order Count Housekeeping Per Sq Ft],
[Measures].[Work Order Count],
[Measures].[House Keeping Square Footage]} ON 0,
[Locations] ON 1
FROM [Work Order]
WHERE ( { [Department].[Department Name].[Housekeeping]},
{ [Event Start Dates].[Date Key].[20160705] : [Event Start Dates].[Date Key].[20180705] },
{ [Owner Entity].[Entity ID].[12279], [Owner Entity].[Entity ID].[12280], [Owner Entity].[Entity ID].[14067], [Owner Entity].[Entity ID].[15092]},
{ [Work Order Days Open].[Days Open].[1] : [Work Order Days Open].[Days Open].[250] },
{ [Work Order Days Overdue].[Days Overdue].[1] : [Work Order Days Overdue].[Days Overdue].[250] } )
Related
I need two join two queries, I tried with members but it didn't work. I am new to MDX, please let me know if there a way of doing this. Error is due to list in the calculated member.
SELECT NON EMPTY { [RR TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Unit Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
,-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]} )
SELECT NON EMPTY { [RT TYPE].[Item].[Item].ALLMEMBERS * [Measures].[Price Value] } ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM (SELECT [CCTYPE].[Desc].&[FCD] ON COLUMNS
FROM [GLCube])
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Combined query
WITH MEMBER [Measures].[Unit Value]] AS
(-{[Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},[Measures].[Unit Value])
MEMBER [Measures].[Price Value] AS
( [CCTYPE].[Desc].&[FCD],[Measures].[Price Value] )
SELECT NON EMPTY {[Measures].[Unit Value],[Measures].[Price Value]} ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS} ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010])
Expected Output
WITH
MEMBER [Measures].[Filtered Unit Value] as
Aggregate(
-{ [Ledger].[ID].&[A1],[Ledger].[ID].&[A2] ,[Ledger].[ID].&[A3]},
[Measures].[Unit Value]
)
SELECT NON EMPTY
{
[RR TYPE].[Item].[Item].ALLMEMBERS
* {[RT TYPE].[Item].[All]}
* { [CCTYPE].[Desc].[All]}
* [Measures].[Filtered Unit Value]
}
+
{
{[RR TYPE].[Item].[All]}
* [RT TYPE].[Item].[Item].ALLMEMBERS
* { [CCTYPE].[Desc].&[FCD]}
* [Measures].[Price Value]
}
ON COLUMNS,
NON EMPTY { ([FFS].[FFSCD].[FFSCD].ALLMEMBERS) } ON ROWS
FROM [GLCube]
WHERE ( [Location].[Site Name].&[Sandbox]
, [LT DT].[DATE HIERARCHY].[YEAR].&[2010]
)
I have built this query through BIDS Query Designer. But I want to optimize this query by removing SELECTS inside outermost FROM Clause and having only cube in from clause and rest filter on where or filter clause:
SELECT { [Measures].[User ID Distinct Count], [Measures].[Post Count], [Measures].[Like Count], [Measures].[Comment Count], [Measures].[Impressions Master Count] } ON COLUMNS,
NON EMPTY { ([Section Master].[Section Name].[Section Name].ALLMEMBERS * [Post Master].[Post Name].[Post Name].ALLMEMBERS * [Post Master].[SP Insert Date].[SP Insert Date].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( STRTOSET(#SectionMasterSectionName) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(#FromDimDateDate) : STRTOMEMBER(#ToDimDateDate) ) ON COLUMNS
FROM [AnalyticsCube]))
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
I am quite new in MDX and don't know much in regards to MDX query optimization. And Because of that I also don't know that this is the Optimized version of query or there is still scope for optimization in this. My cube structure is shown in Image.
I have Update my old query by doing some changes in Row and Column Part, but still stuck with From Clause part
SELECT { [Measures].[User ID Distinct Count],
[Measures].[Post Count],
[Measures].[Like Count],
[Measures].[Comment Count],
[Measures].[Impressions Master Count] } ON COLUMNS,
NON EMPTY { ([Section Master].[Section Name].CHILDREN) *
([Post Master].[Post Name].CHILDREN, [Post Master].[SP Insert Date].CHILDREN ) } ON ROWS
FROM ( SELECT ( STRTOSET(#SectionMasterSectionName) ) ON COLUMNS
FROM ( SELECT ( STRTOMEMBER(#FromDimDateDate) : STRTOMEMBER(#ToDimDateDate) ) ON COLUMNS
FROM [AnalyticsCube]))
This would be the initial simplification:
SELECT
{
[Measures].[User ID Distinct Count]
,[Measures].[Post Count]
,[Measures].[Like Count]
,[Measures].[Comment Count]
,[Measures].[Impressions Master Count]
} ON COLUMNS
,NON EMPTY
{
[Section Master].[Section Name].Children
*
(
[Post Master].[Post Name].Children
,[Post Master].[SP Insert Date].Children
)
} ON ROWS
FROM
(
SELECT
StrToSet(#SectionMasterSectionName) ON 0,
StrToMember(#FromDimDateDate) : StrToMember(#ToDimDateDate) ON 1
FROM [AnalyticsCube]
);
Then it seems odd to me that you don't move StrToSet(#SectionMasterSectionName) into the main SELECT clause:
SELECT
{
[Measures].[User ID Distinct Count]
,[Measures].[Post Count]
,[Measures].[Like Count]
,[Measures].[Comment Count]
,[Measures].[Impressions Master Count]
} ON COLUMNS
,NON EMPTY
{
StrToSet(#SectionMasterSectionName)
*
(
[Post Master].[Post Name].Children
,[Post Master].[SP Insert Date].Children
)
} ON ROWS
FROM
(
SELECT
StrToMember(#FromDimDateDate) : StrToMember(#ToDimDateDate) ON 0
FROM [AnalyticsCube]
);
Logically it is slightly different but you could then think about using a WHERE clause rather than a SUB-SELECT:
SELECT
{
[Measures].[User ID Distinct Count]
,[Measures].[Post Count]
,[Measures].[Like Count]
,[Measures].[Comment Count]
,[Measures].[Impressions Master Count]
} ON COLUMNS
,NON EMPTY
{
StrToSet(#SectionMasterSectionName)
*
(
[Post Master].[Post Name].Children
,[Post Master].[SP Insert Date].Children
)
} ON ROWS
FROM [AnalyticsCube]
WHERE
StrToMember(#FromDimDateDate) : StrToMember(#ToDimDateDate);
I am using Built in time intelligence feature and I would like to calculate measures for the Full Year.
Eg if current member of date is at 2015/03/01; I want to have a calculated measure from 2015/01/01 till 2015/12/31.
CREATE MEMBER CurrentCube.[DimTime].[FY-FQ-FM DimTime Calculations].[Full Year] AS "NA" ;
(
[DimTime].[FY-FQ-FM DimTime Calculations].[Year to Date]
, [DimTime].[Fiscal Year].[Fiscal Year].Members
, [DimTime].[Date].Members
, { [Measures].[Forecasts], [Measures].[Budget] }
)
= Aggregate(
{ [DimTime].[FY-FQ-FM DimTime Calculations].[Current DimTime] }
* PeriodsToDate(
[DimTime].[FY-FQ-FM].[Fiscal Year]
, [DimTime].[FY-FQ-FM].CurrentMember
)
) ;
Thanks #whytheq and #AkshayRane for the help.
I was able to do the full year using below.
(
[DimTime].[FY-FQ-FM DimTime Calculations].[Full Year],
[DimTime].[Fiscal Year].[Fiscal Year].Members,
[DimTime].[Date].Members,
{
[Measures].[Forecasts],
[Measures].[Budget]
}
)
=
Aggregate(
{ [DimTime].[FY-FQ-FM DimTime Calculations].[Current DimTime] }
*
PeriodsToDate(
[DimTime].[FY-FQ-FM].[Fiscal Year],
(
ANCESTOR(
[DimTime].[FY-FQ-FM].CURRENTMEMBER,
[DimTime].[FY-FQ-FM].[Fiscal Year]
)
)
)
)
This is my MDX Query.
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
{(
[Products].[Item Description].children,
[Calendar].[Date].[Date]
)}
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
This gives the sales records in quantity and net sales as expected. We need now to sort it to get the item which has the highest quantity in first. In other words, we're looking to apply 'descending' sort here.
I tried all order method which gives me error. Can you please help me to get my wish done?
Have you tried the below ?
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER((
[Products].[Item Description].children,
[Calendar].[Date].[Date]
), [Measures].[Quantity], DESC)
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
Second attempt [WORKING SOLUTION]
select
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
on columns,
NON EMPTY
ORDER((
[Products].[Item Description].children
), [Measures].[Quantity], DESC)
*[Calendar].[Date].[Date]
on rows
from
(
select
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON columns
FROM [SalesReport])
If you wanted to further order the inner group you could do this:
SELECT
{
[Measures].[Quantity],
[Measures].[Net Sales]
}
ON 0,
NON EMPTY
GENERATE(
ORDER(
[Products].[Item Description].children
,[Measures].[Quantity], BDESC)
,
ORDER(
[Products].[Item Description].CURRENTMEMBER //<< possibly [Products].CURRENTMEMBER
*
{[Calendar].[Date].[Date].Members}
,[Measures].[Quantity], BDESC))
ON 1
FROM
(
SELECT
{
[Calendar].[Date].&[2015-03-23T00:00:00],
[Calendar].[Date].&[2015-03-22T00:00:00],
[Calendar].[Date].&[2015-03-21T00:00:00]
}
ON 0
FROM [SalesReport]
);
I have this MDX query
select
{
[Measures].[Sold value]
,[Measures].[Units]
,[Measures].[Sales baskets]
,[Measures].[ATV]
,[Measures].[AUT]
} on columns
, filter(
nonempty(
{[Branch].[Branch].&[5] *[Receipt No - Sales].[Receipt No].[Receipt No]}
),
[Measures].[Sold value] >= 50
) on rows
from Rmis
where [Time].[Day].&[20131218]
Which generates following result:
How can I get the total of these measures of the above result set? The total should use the aggregation defined in the cube.
with set [rows] as
filter(
nonempty(
{[Branch].[Branch].&[5] *[Receipt No - Sales].[Receipt No].[Receipt No]}
),
[Measures].[Sold value] >= 50
)
member [Receipt No - Sales].[Receipt No].[Total] as
aggregate([rows])
select
{
[Measures].[Sold value]
,[Measures].[Units]
,[Measures].[Sales baskets]
,[Measures].[ATV]
,[Measures].[AUT]
} on columns
,
{ ([Branch].[Branch].&[5], [Receipt No - Sales].[Receipt No].[Total]) }
+
[rows]
on rows
from Rmis
where [Time].[Day].&[20131218]