I am trying to select top max 10 measure in MDX and I get this ,what I have to do to get top 10 max.
With
Set [Top10] AS
(TOPCOUNT({ORDER( ({[Customer].[Customer State]})
,([Measures].[Customers Quantity]),BDESC)},10))
Select
[Measures].[Customers Quantity] on Columns,
{[Top10]} on Rows
From
[DW Brazillian Ecommerce]
and I get this
I know what I did is wrong so what is the accurate query to get top 10 max customer quantity??
Change [Customer].[Customer State] to [Customer].[Customer State].[Customer State].Members. In the current expression you are just ranking the grand total. This change fixes the problem.
Related
In my cube I have
Earnings as measure with MIN aggregation
Dimension: [Localization].[Type].&[center]
Dimension: {[Date].[Year].&[2017], [Date].[Year].&[2018]}
My query is:
What are the minimum earnings of the person who decides to buy
apartments in the city center, excluding 5% of the lowest, within
last 2 years?
Now my mdx query looks like that:
SELECT
[Measures].[MinEarnings] ON COLUMNS
FROM [cube]
WHERE
(
BottomCount ([Localization].[Type].&[center], 95, [Measures].[MinEarnings]),
{[Date].[Year].&[2017], [Date].[Year].&[2018]}
)
I have two problems:
Some earnings are 0 - how can I skip them in calculations?
If my query correctly excludes 5% of the lowest earnings?
First of all you should use toppercent not bottomcount. you want the min salary of a person who is not in last 5% not last 5. Toppercent will give you the top 95%.
Secondly to filter 0 you can use the following syntax
toppercent (
filter([Localization].[Type].&[center], [Measures].[MinEarnings]>0)
, 95, [Measures].[MinEarnings])
Even now placing the code in the where clause might not work, however try it. I would suggest that you move the toppercent to rows , then order it, then take the top1
topcount(
order(
toppercent (
filter([Localization].[Type].&[center], [Measures].[MinEarnings]>0)
,95, [Measures].[MinEarnings])
,[Measures].[MinEarnings],asc)
,1)
I have an example which gives the minum sales amount of cities, notice i have replaced nulls with 0 to make it as close as possible to your case
with member [Measures].[Internet Sales Amount2]
as
case when ([Measures].[Internet Sales Amount])=null then 0 else [Measures].[Internet Sales Amount] end
select [Measures].[Internet Sales Amount2]
on columns ,
topcount(order(toppercent(filter([Customer].[City].[City],[Measures].[Internet Sales Amount2]>0),95,[Measures].[Internet Sales Amount2]),[Measures].[Internet Sales Amount2],asc),1)
on rows
from [Adventure Works]
where [Customer].[Country].&[Canada]
in the picture below is the result before topcount 1
I am newbie to SSAS cube and need some help. I have a cube created from a fact table and one of the measure, lets call it amount, contains zeros. This measure was created as a SUM.
Now I also have the Count measure added by SSAS designer.
What I need is the count of all non zero amount.
I tried to add a calculated measure as
`IIF([Measures].[amount] > 0,[Measures].[RowCount],null)`
also tried
FILTER([Measures].[RowCount],[Measures].[Amount] > 0)
Both these returns the count including the amount=0.
I am validating it via SSMS sql query
SELECT count(*)
FROM [dbo].[Fact_Session]
where SiteKey = 5 and DateKey = 20170201
and Amount >0
Any help is appreciated. My assumption is that the IIF/Filter statement will operate on the individual rows before cubing, as once aggregated into a dimension, the amount will not be 0 due to the aggregation . Please Help.
To count non-zero you can use this approach:
WITH
MEMBER [Measures].[IsNotEmpty] AS
IIf(
Not(IsEmpty([Measures].[Amount]))
,1
,Null
)
But better to do this inside a SUM over a particular set - so the following counts how many subcategories are not empty:
WITH
MEMBER [Measures].[SubCategory_IsNotEmpty] AS
SUM(
[Product].[Product Categories].[SubCategory].members
,IIf(
Not(IsEmpty([Measures].[Amount]))
,1
,Null
)
)
I'm currently working with MDX in pentaho.
Currently I'm facing issue is that Unable to get top 10 count based on a Measure.
i.e., I want to write MDX query for find top 10 customer's based on Current year Sales volume and also needed Previous year sales amount for that customers.
My Problem is that MDX query Sum the Previous and Current year sales volume and listed out the top 10.
How can i get top 10 based on Current year column?
For Example,
Customer Current Year Previous Year
A 100 200
B 150 125
C 200 -
Expected Result:
Customer Current Year Previous Year
C 200 -
B 150 125
A 100 200
Please help me out.
The Topcount function takes 3 arguments, a Set, the number of items to return and a numeric expression.
Supposing you have [Customer].Members on Rows, two [Time] dimension members already defined and [Measures].[Sales] as your measure, you can use
Select
TopCount( [Customer].Members, 3, ( [Measures].[Sales], [Time].[Current Year]) ) on Rows,
{ [Time].[Current Year], [Time].[Previous Year] } on Columns
From [My Cube]
Where [Measures].[Sales]
The TopCount will return the top 3 customers, based on their rank by
([Measures].[Sales], [Time].[Current Year])
If you don't specify this tuple as the numeric expression you get the rank by the overall [Measures].[Sales] value.
Documentation: http://technet.microsoft.com/en-us/library/ms144792.aspx
I want to create a barchart with a bar for each month and some measure.
But i also want to filter on a range of day which might not completly overlap some of the month.
When that happen I would like the aggregate count for those month to only aggregat over the days that fall in my date range not get the aggregate for the whole month.
Is that possible with MDX and if it is how should the request look like?
Create a second time dimension, using a virtual dimension of the original dimension. Use one dimension in the WHERE and another in the SELECT.
This often happens anyway if some people want 'Business Time' of quarters and periods, and others prefer months. Or if you have a financial year which runs April-April.
You can use subselect. You can find more information on this page and this page:
When a member is specified in the axis clause then that member with
its ascendants and descendants are included in the sub cube space for
the subselect; all non mentioned sibling members, in the axis or
slicer clause, and their descendants are filtered from the subspace.
This way, the space of the outer select has been limited to the
existing members in the axis clause or slicer clause, with their
ascendants and descendants as mentioned before.
Here is an example:
SELECT { [Customer].[Customer Geography].[Country].&[Australia]
, [Customer].[Customer Geography].[Country].&[United States]
} ON 1
, {[Measures].[Internet Sales Amount], [Measures].[Reseller Sales Amount]} ON 0
FROM ( SELECT {[Customer].[Customer Geography].[Country].&[Australia]
, [Customer].[State-Province].&[WA]&[US]} ON 0
FROM [Adventure Works]
)
The result will contain one row for Autralia and another one for the United States. With the subselect, I restricted the value of United Stated to the Washington state.
One way I found to do it with Mondrian is as follow
WITH MEMBER [Measures].[Units Shipped2] AS
SUM
(
{
exists([Store].[Store Country].currentmember.children,{[Store].[USA].[WA],[Store].[USA].[OR]})
},[Measures].[Units Shipped]
)
MEMBER [Measures].[Warehouse Sales2] AS
SUM
(
{
exists([Store].[Store Country].currentmember.children,{[Store].[USA].[WA],[Store].[USA].[OR]})
},[Measures].[Warehouse Sales]
)
SELECT
{[Measures].[Units Shipped2],[Measures].[Warehouse Sales2]} ON 0,
NON EMPTY [Store].[Store Country].Members on 1
FROM [Warehouse]
I am not sure if the filtering will be done in SQL like below and give good performance or be run locally
select Country, sum(unit_shipped)
where state in ('WA','OR' )
group by Country
How can I compute average of sums in MDX? I want to compute sum of spending for each person and then compute an average of it. I have the following query so far, but I believe it gives me wrong result:
WITH MEMBER [Measures].[Average] AS
AVG(Measures.cost)
SELECT [Measures].[Average] ON COLUMNS
FROM
( SELECT Measures.cost ON COLUMNS,
{Person.[Last name].MEMBERS}*
{Person.[First name].MEMBERS} ON ROWS
FROM Cube )
Any help would be greatly appreciated.
You just need to put in the first argument of Avg the set of your persons.
WITH MEMBER [Measures].[Average] AS
AVG(Person.[Last name].MEMBERS * Person.[First name].MEMBERS, Measures.cost)
SELECT [Measures].[Average] ON COLUMNS
FROM Cube
Try to create a calculated measure for this function like this
IIF (([Measures.cost] > 0), AVG(Person.Members,Measures.cost),null)
Then use this calculated measure in your MDX query
SELECT Person, 'calculated.measure'
FROM Cube
This is only a sample code to illustrate the function.