I can get the MAX() of some Measure based on Dimensions specified. I have no issues with that. What I am looking for is Second MAX(). Means if I sort the some Measures in DESC order it is 5,4,3,2,1
With MAX() I can get 5 but I want 4. How do I compute that?
Use the EXCEPT keyword to knock out the top one from the top two set:
SELECT
[Measures].[YourMeasure]
ON 0,
NON EMPTY
{
EXCEPT
(
TOPCOUNT( [Date].[Date].[Date], 2, [Measures].[YourMeasure] ),
TOPCOUNT( [Date].[Date].[Date], 1, [Measures].[YourMeasure] )
)
}
ON 1
FROM [YourCube]
Related
I'm attempting to get the top 10 countries by value from any measures where the discount rate is -20, and for a specific date. I've created a simple dynamic set defined as:
CREATE DYNAMIC SET CURRENTCUBE.[Top10CountryBy20Disc]
AS
TopCount
( [Customer].[Country].members,
10, [Discount].[Discount].&[-20%])
;
This gives me the top 10 customers summed by the overall measure value, but I need to filter to a specific date. The overall top 10 won't be the same as the top 10 on a particular date, so I need to include some date context. Currently the numbers I get back for each country are correct, but it is the list of countries (the top 10 list) that is incorrect.
I use the set [Latest] listed below in a lot of other reports, and this works just fine, but am struggling to combine this when using the above set.
CREATE DYNAMIC SET CURRENTCUBE.[Latest]
AS FILTER(
[Date].[Date Key].[Date Key].members, IsDate([Date].[Date Key].currentmember.membervalue)
AND (
DateDiff("d", [Date].[Date Key].currentmember.membervalue, IIF(Weekday(Now()) = 2, 3, 1)
);
Logically I am trying to do something along the lines of the below, which is invalid syntax:
TopCount
( [Customer].[Country].members,
10, ([Discount].[Discount].&[-20%], [Latest]))
;
Would be grateful for some suggestions/direction on this.
This approach solved my issue:
GENERATE ( [Latest],
{TopCount
( descendants([Customer].[Country],,AFTER),
10,
VBA!Abs(([Discount].[Discount].&[-20%], ([Measures].[MeasureName],[Date].[Date Key].currentmember)))
)
}
);
I want to show a list of callers we have missed calls from within a daterange. I want te result to be ordered by date. But I can't figure out how to do this.
My MDX statement:
With
Member [Measures].[Gemist] AS
sum(
except({[CM resultaat].[Resultaat].[CM resultaat].allmembers},
{[CM resultaat].[Resultaat].[CM resultaat].[answer],[CM resultaat].[Resultaat].[CM resultaat].[answer overflow]}),
[Measures].[SN Gesprekken]
)
Select
order([Measures].[Gemist],[Datum].[Datum].currentMember.value, ASC) on 0,
nonempty(crossjoin(Hierarchize([ServiceNummer ANI].[Ani]),[Datum].[Datum].[Dag]),[Measures].[Gemist]) on 1
FROM (SELECT {[datum].[datum].[dag].[2020-04-01]:[datum].[datum].[dag].[2020-04-28]} ON 0 FROM [Cube])
After some google searches I tried this to order the measure by date but also tried to order the crossjoin. Output stays te same, no order on date:
Anyone has a solution for this?
You need to order the vertical axis (i.e., the axis 1):
order(
nonempty(
crossjoin( [ServiceNummer ANI].[Ani], [Datum].[Datum].[Dag] )
),
[Datum].[Datum].currentMember.key,
BASC
) on 1
using the key (or name) of the current member of the [Datum] dimension.
Hope that helps.
Good Day all.
I really hope someone can assist with this. The following code works great in DaxStudio and returns a topn table.
evaluate
TOPN(10,SUMMARIZE(factDailyPlay,factDailyPlay[PlayerAccountNumber],"Top10",SUM(factDailyPlay[ActualWin])),[Top10],0)
What I am trying to return in my model though is sum of those top 10 values as a single scalar value of that topn table.
I keep getting the following error.
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
Thanks
Try using:
EVALUATE
ROW (
"Total", SUMX (
TOPN (
10,
SUMMARIZE (
factDailyPlay,
factDailyPlay[PlayerAccountNumber],
"Top10", SUM ( factDailyPlay[ActualWin] )
),
[Top10], 0
),
[Top10]
)
)
Basically the below expression calculates the sum you require.
SUMX (
TOPN (
10,
SUMMARIZE (
factDailyPlay,
factDailyPlay[PlayerAccountNumber],
"Top10", SUM ( factDailyPlay[ActualWin] )
),
[Top10], 0
),
[Top10]
)
I created a query which calculates variance level on sales and the percentage on the variance. However, my query returns NULL whenever I try to test against the CostSales measure!
IIF(
IsEMPTY(
(
ParallelPeriod
(
[Time].[CalendarSales].[CalendarYear],
1,
[Time].[CalendarSales].CurrentMember
),[Measures].[CostSales]
)
)
OR
(
ParallelPeriod
(
[Time].[CalendarSales].[CalendarYear],
1,
[Time].[CalendarSales].CurrentMember
),[Measures].[CostSales]
)=0
,
0,
[Measures].[ParallelPeriodFactSalesVariance]/[Measures].[ParellelPeriodFactSales]
)
Any idea of what I am doing wrong here?
If you are not getting 0 returned then I'd assume that there is a problem with [Measures].[ParallelPeriodFactSalesVariance]/[Measures].[ParellelPeriodFactSales]
Two diagnostics you can run are:
1.Change the whole measure to this:
IIF(
IsEMPTY(
(
ParallelPeriod
(
[Time].[CalendarSales].[CalendarYear],
1,
[Time].[CalendarSales].CurrentMember
),[Measures].[CostSales]
)
)
OR
(
ParallelPeriod
(
[Time].[CalendarSales].[CalendarYear],
1,
[Time].[CalendarSales].CurrentMember
),[Measures].[CostSales]
)=0
,
0,
999
)
I'd imagine 999 is being returned. If it is then try changing the custom member to just this:
[Measures].[ParallelPeriodFactSalesVariance]/[Measures].[ParellelPeriodFactSales]
Is NULL now being returned? So this is the problem - but as Greg's comment suggests we need to see the code for these two measures - also, as context is important, we could do with seeing the full script where your code is being used.
I would like to order a set of results in an MDX query which also includes a crossjoin.
I have the following measures and dimensions:
[Measures].[Starts]
[Framework].[Framework Name]
[Framework].[Pathway Name]
I would like to create a list of the (corresponding) Framework and Pathway names that correspond to the top 25 numbers of [Measures].[Starts].
I have managed to output a FULL list of results using:
select [Measures].[Starts] on COLUMNS,
NON EMPTY CrossJoin(
Hierarchize({DrilldownLevel({[Framework].[Pathway Name].Children})}),
Hierarchize({DrilldownLevel({[Framework].[Framework Name].Children})})
) on ROWS
from [DataCube]
to create the following example output:
However, I need it to be sorted by the starts in descending order (and preferably only keep the top 25 results). I have tried almost everything and have failed. A google search didn't find any results.
Did you stumble across the TopCount function?
select [Measures].[Starts] on COLUMNS,
NON EMPTY
TopCount
(
CrossJoin
(
Hierarchize({DrilldownLevel({[Framework].[Pathway Name].Children})}),
Hierarchize({DrilldownLevel({[Framework].[Framework Name].Children})})
),
25,
[Measures].[Starts]
) on ROWS
from [DataCube]
Here's the msdn link.
H2H
For efficiency it is better to order the set before using the TopCount function:
WITH
SET [SetOrdered] AS
ORDER(
{DrilldownLevel([Framework].[Pathway Name].Children)}
*{DrilldownLevel([Framework].[Framework Name].Children)}
,[Measures].[Starts]
,BDESC
)
SET [Set25] AS
TOPCOUNT(
[SetOrdered]
,25
)
SELECT
[Measures].[Starts] on 0,
NON EMPTY
[Set25] on 1
FROM [DataCube];