I want to return Total Sales for 2019 for County = X OR City = Y.
How can I do that?
This returns error:
SELECT
{[Measures].[Total Sales]} ON 0,
{[Date].[Date].[Year].&[2019]} ON 1
FROM [Cube]
WHERE
{([County].[County].[X]),([City].[City].[Y])}
Two sets specified in the function have different dimensionality.
You need to address the hierarchility and dimensionality of the sets. Use the sample below.
SELECT
{[Measures].[Total Sales]} ON 0,
{[Date].[Date].[Year].&[2019]} ON 1
FROM [Cube]
WHERE
{
([County].[County].[X],[City].[City].defaultmember),
([County].[County].defaultmember,[City].[City].[Y])
}
Related
in MDX I would like to create a select which returns a 2x2 array, filled with hard coded values.
Here is an attempt:
WITH
MEMBER a AS 1
MEMBER b AS 2
SET un AS { a , b }
SELECT { un} ON 0,
[Dim misc].[Gender].[(All)] ON 1
FROM [my cube]
it returns:
but I would like it to return an other row, with other values than 1,2.
You have solved half the problem already. However defining a set is not necessary.
You need to do the following
Use defaultmember,
Use Case
Define a dummy member for the dimension you use.
Instead of Set just define members.
Take a look at the example below based on adventure works.
with
member Column1Row1 as 1
member Column2Row1 as 2
member Column1Row2 as 3
member Column2Row2 as 4
member Column1 as case when [Product].[Product].currentmember is [Product].[Product].defaultmember then Column1Row1 else Column1Row2 end
member Column2 as case when [Product].[Product].currentmember is [Product].[Product].defaultmember then Column2Row1 else Column2Row2 end
member [Product].[Product].[Row2]
as [Product].[Product].defaultmember
select
{Column1,Column2} on 0,
{
[Product].[Product].defaultmember,
[Product].[Product].[Row2]}
on 1
from
[Adventure Works]
Result
I need to merge the result 2 queries into one table. Queries are similar except one of WHERE conditions.
As far as I was able to find out while googling it is impossible to do as MDX have internal connections in database design.
I have tried to use this way: Merge 2 MDX queries
But it turns out that in 1 hour I get this error:
XML for Analysis parser: The XML for Analysis request timed out before it was completed.
I have tried to make new members like that:
member new_A AS
aggregate
(
K
,
A
)
And then
select { new_A, ...
select { A , B , C , D } on 0,
non empty { Y * Z } on 1
from X
where (except(K), L, M, N, P);
select { A , B , C , D } on 0,
non empty { Y * Z } on 1
from X
where (K, L, M, N, P);
What I need to get in the end is a table that contains values of elements A,B,C,D as columns for condition K only and for all except condition K just next to it. it can be either A, new_A, B, new_B, etc or A, B, C, D , new_A, new_B, etc.
P.S. database is extremely big and the faster it works the better :)
So i have tried to map your problem to AdventureWorks sample database.
In my problem i am trying report [internet Sales Amount] for some countries for a set of subcategories. Then I edit my query to report all subcategories except "Road Bikes" in main columns and for road bikes i use measures.RoadBikes.
Query 1
with member
measures.RoadBikes
as
( ([Product].[Subcategory].&[2],[Measures].[Internet Sales Amount]))
select
non empty
{
({[Customer].[Country].&[Australia],[Customer].[Country].&[Canada],[Customer].[Country].&[France],[Customer].[Country].&[United Kingdom],[Customer].[Country].&[United States]},
[Measures].[Internet Sales Amount]
),
({[Customer].[Country].&[Australia],[Customer].[Country].&[Canada],[Customer].[Country].&[France],[Customer].[Country].&[United Kingdom],[Customer].[Country].&[United States]},
measures.RoadBikes
)
}
on columns,
non empty
[Date].[Month of Year].[Month of Year]
on
rows
from
[Adventure Works]
where
({[Product].[Subcategory].&[31],[Product].[Subcategory].&[1],[Product].[Subcategory].&[2],[Product].[Subcategory].&[37],[Product].[Subcategory].&[3]})
Result
Edit the query
with member measures.UsRoadBikes as ([Product].[Subcategory].&[2],[Measures].[Internet Sales Amount])
select non empty
{({[Customer].[Country].&[Australia],[Customer].[Country].&[Canada],[Customer].[Country].&[France],[Customer].[Country].&[United Kingdom],[Customer].[Country].&[United States]},
[Measures].[Internet Sales Amount])}
on columns,
non empty
({[Product].[Subcategory].&[31],[Product].[Subcategory].&[1],[Product].[Subcategory].&[2],[Product].[Subcategory].&[37],[Product].[Subcategory].&[3]},
[Date].[Month of Year].[Month of Year]
) on rows
from [Adventure Works]
Result
Thanks everyone!
It was decided to run queries in parallel to speed up.
Return data to be populated into dataset and then Linq to be used to work with it.
I have a day level in my time dimension.
I want to output the sum/avg for a selected range of days like in the following statement:
WITH
MEMBER measures.[sum1] AS
Sum([Measures].[Menge_Artikel_Stk])
MEMBER measures.[sum2] AS
Sum
(
[D_Datum].[Datum].[Tag]
,[Measures].[Menge_Artikel_Stk]
)
SELECT
{
[Measures].[stock]
,[Measures].[sum1]
,[Measures].[sum2]
} ON 0
,NON EMPTY
CrossJoin
(
{[D_item].[itemno].[itemno].MEMBERS}
,{
[D_Date].[Date].[day].[30.01.2017] : [D_Date].[Date].[Day].[05.02.2017]
}
) ON 1
FROM [Cube];
My goal is to show the sum/avg along the date-dimension filtered on rows.
Instead of 40/1653 i want sum to display 250 for the sum or 35,7 for the average. (1653 is obviously the sum of the entire day level). I want to add this calculated member to an Excel-Sheet. Thus the time range set is variable.
To get the sum/avg rows across the specific range you can do something like this:
WITH
MEMBER measures.[sum1] AS
Sum([Measures].[Menge_Artikel_Stk])
MEMBER measures.[sum2] AS
Sum
(
[D_Datum].[Datum].[Tag]
,[Measures].[Menge_Artikel_Stk]
)
MEMBER [D_Date].[Date].[All].[DaySum] AS
Sum
(
[D_Date].[Date].[day].[30.01.2017] : [D_Date].[Date].[Day].[05.02.2017]
)
MEMBER [D_Date].[Date].[All].[DayAvg] AS
Avg
(
[D_Date].[Date].[day].[30.01.2017] : [D_Date].[Date].[Day].[05.02.2017]
)
SELECT
{
[Measures].[stock]
,[Measures].[sum1]
,[Measures].[sum2]
} ON 0
,NON EMPTY
CrossJoin
(
{[D_item].[itemno].[itemno].MEMBERS}
,{
{
[D_Date].[Date].[day].[30.01.2017] : [D_Date].[Date].[Day].[05.02.2017]
}
,[D_Date].[Date].[All].[DaySum]
,[D_Date].[Date].[All].[DayAvg]
}
) ON 1
FROM [Cube];
You can use the Axis function to define the current set on your axis:
WITH
MEMBER measures.[sum] AS
Sum(
Axis(1),
[Measures].[Menge_Artikel_Stk]
)
MEMBER measures.[avg] AS
AVG(
Axis(1),
[Measures].[Menge_Artikel_Stk]
)
SELECT
{[Measures].[Menge_Artikel_Stk],[Measures].[sum],[Measures].[avg]} ON 0,
NON EMPTY {[D_Date].[Date].[day].[30.01.2017]:[D_Date].[Date].[Day].[05.02.2017]} ON 1
FROM [Cube];
Let's say I have two simple dimensions:
Products - with id and name
Salesmen - with id and name
My fact table is named SALES and contains the ids of the abovementioned.
I need to produce a query that will show the names of salesmen who sold all of the given products.
This code solves the problem for two items X and Y:
SELECT
{} on 0,
EXISTS(
EXISTS(
{[Salesmen].[Name].MEMBERS},
{[Products].[Name].&[X]}
)
,{[Products].[Name].&[Y]}
)
ON 1
FROM [Test];
The other version is:
SELECT
{} on 0,
INTERSECT(
NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,([Products].[Name].&[X])
)
,NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,([Products].[Name].&[Y])
)
)
ON 1
FROM [Test];
However, this method becomes troublesome if the list of given products is large, for example - 100 random products..
Do you have a property member_key for the hierarchy [Products].[Name] ? We can test like this:
WITH
MEMBER [Measures].[Meas1] AS
[Products].[Name].CurrentMember.PROPERTIES("KEY ID")
MEMBER [Measures].[Meas2] AS
[Products].[Name].CurrentMember.MEMBER_Key
MEMBER [Measures].[Meas3] AS
[Products].[Name].CurrentMember.MEMBERvalue
select
{
[Measures].[Meas1]
,[Measures].[Meas2]
,[Measures].[Meas3]
} on COLUMNS,
[Products].[Name].MEMBERS on ROWS
FROM [Test];
Hopefully one of the custom measures gives you a value? I'll assume Meas2 is working (swap to a different one if Meas1 or Meas3 is returning numbers)
WITH
MEMBER [Measures].[Meas2] AS
[Products].[Name].CurrentMember.MEMBER_Key
SET [ProdsetA] AS
FILTER(
[Products].[Name].MEMBERS
,[Measures].[Meas2] <100
)
SET [ProdsetB] AS
FILTER(
[Products].[Name].MEMBERS
,[Measures].[Meas2] >500
)
SELECT
{} on 0,
INTERSECT(
NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,[ProdsetA]
)
,NONEMPTY(
{[Salesmen].[Name].MEMBERS}
,[ProdsetB]
)
)
ON 1
FROM [Test];
... the >100 and <500 are important. These are the criteria for the filter function to use. The custom set [ProdsetA] will only contain Products that have MEMBER_Key that are <100 whereas the custom set [ProdsetB] will only contain Products that have MEMBER_Key that are >500. You need to use the member values presented to you by the first script to decide what values 100 and 500 should be in your cube context (...I don't know the key values in your cube so just used 100 and 500 as placeholders)
I have the following Problem:
Select
{
[Measures].[PerformanceTotalYtd]
} on columns,
Non Empty{
Except(([Desk].[DeskName].[Trade].Members,[Time].[Year-Month-Day].[Day].&[2012]&[1]&[10]),([Desk].[DeskName].[Trade].Members,[Time].[Year-Month-Day].[Day].&[2012]&[1]&[09]))
} on rows
from [Cube]
where ([Entity].[Entity].&[9], [Audience].[View].&[GOD])
It exists a Dimension with the Name Desk. This Dimension has a Hierarchy with the name DeskName. The lowest Level ist Trade.
Desk: -Total -Segment -BusinessArea -Department -4th Level Portfolio -Desk -Trade
With the Query showing below, i want to show all Trades, that have the Measure "PerformanceTotalYtd" != NULL on the Date of 2012/01/10 except the Trades with the Measure "PerformanceTotalYtd" != NULL on the Date of 2012/01/09 !
Example:
Trades with Measure PerformanceTotalYtd on the 2012/01/10:
ABC 12,99
DEF 3,22
GHI 55,60
Trades with Measure PerformanceTotalYtd on the 2012/01/09:
ABC 80,00
DEF 8,78
I want the following Result because the Trade "GHI" doesn't exists on the 2012/01/09 and is new:
GHI 55,60
My Query showing below have this result:
ABC 12,99
DEF 3,22
GHI 55,60
It doesn't delete the existing Trades from the 2012/01/09.
I have a Solution in SQL but want to make it in MDX:
SELECT DD.Code, Sum(PerformanceTotalYtd) as TOTAL
FROM [Reporting_DB].[Star].[Fact_PerformanceTotal] FIS
inner join Star.Dimension_Desk DD on FIS.DeskID = DD.DeskID
WHERE FIS.TimeID = 20120110 and FIS.EntityID = 9 AND DD.Code not in ( SELECT DD.Code
FROM [Reporting_DB_HRE].[Star].[Fact_PerformanceTotal] FIS inner join Star.Dimension_Desk DD on FIS.DeskID = DD.DeskID WHERE FIS.TimeID = 20120109 and FIS.EntityID = 9 group by DD.Code)group by DD.Code
Can anybody help me please? I can't find a solution.
Sorry for my bad english!
Alex
I have found a similar example in the Adventure Works cube:
The set {[Customer].[City].&[Bell Gardens]&[CA], [Customer].[City].&[Bellevue]&[WA], [Customer].[City].&[Bellflower]&[CA]} has 3 values for [Measures].[Internet Sales Amount] in [Date].[Calendar Year].&[2002], and only 2 values in [Date].[Calendar Year].&[2004]. So we need to show measure value for member in 2002 where measure value == null in 2004.
The next MDX query achieves the desired result:
with set S as '{[Customer].[City].&[Bell Gardens]&[CA], [Customer].[City].&[Bellevue]&[WA], [Customer].[City].&[Bellflower]&[CA]}'
select
[Measures].[Internet Sales Amount] on 0,
non empty { Filter(S, IsEmpty(([Date].[Calendar Year].&[2004], [Measures].[Internet Sales Amount]))) } on 1
from [Adventure Works]
where ([Date].[Calendar Year].&[2002])
I tried to modify your example accordingly, but can't test it. Here it is:
select
{ [Measures].[PerformanceTotalYtd] } on 0,
non empty { Filter([Desk].[DeskName].[Trade].Members, IsEmpty(([Time].[Year-Month-Day].[Day].&[2012]&[1]&[09], [Measures].[PerformanceTotalYtd]))) } on 1
from [Cube]
where ([Entity].[Entity].&[9], [Audience].[View].&[GOD], [Time].[Year-Month-Day].[Day].&[2012]&[1]&[10])
In short: use Filter instead of Except.
I have the Solution for my Problem. Following Query shows the same Result as the Query of Dmitry Polyanitsa! Have a nice Day guys!
with
set [Trades Today] as NonEmpty([Desk].[DeskName].[Trade].Members, ([Measures].[PerformanceTotalYtd], [Time].[Year-Month-Day].[Day].&[2012]&[1]&[10]))
set [Trades Yesterday] as NonEmpty([Desk].[DeskName].[Trade].Members, ([Measures].[PerformanceTotalYtd], [Time].[Year-Month-Day].[Day].&[2012]&[1]&[9]))
set [Trades Difference] as Except([Trades Today], [Trades Yesterday])
Select
{
[Measures].[PerformanceTotalYtd]
} on columns,
Non Empty{
[Trades Difference]
} on rows
from [Cube]
where ([Entity].[Entity].&[9], [Audience].[View].&[GOD])