MDX: I need only those highlighted records - ssas

I need only those highlighted records.
SELECT
[Measures].[Assessment Patients Detail] ON COLUMNS,
NON EMPTY([DimAssessment].[Assessment Text].&[Employee Wellness HRA],
[DimAssessment].[Question Text].&[Do you use tobacco products?],
[DimPatient].[Patient Key].[Patient Key],
Generate(
[DimAssessment].[Answer Text].[Answer Text].MEMBERS
,[DimAssessment].[Answer Text].CURRENTMEMBER
*TAIL(
NonEmpty(
[DimDate].[Full Date Alternate Key].[Full Date Alternate Key].MEMBERS
,[DimAssessment].[Answer Text].CURRENTMEMBER
)
,[DimAssessment].[Question Text].&[Do you use tobacco products?]
)
)
)ON ROWS
FROM
[Care];

This probably isn't the answer as I've tried to help with this before but the following is a little mysterious:
The second argument of the function Tail is usually an integer e.g. 2 or 3 which means you would like the last 2, or last 3, members from the set specified in first arg of Tail.
I prefer to use cross-join rather than a tuple for members on rows but I don't think this will give you the rows you require:
SELECT
[Measures].[Assessment Patients Detail] ON COLUMNS,
NON EMPTY
{[DimAssessment].[Assessment Text].&[Employee Wellness HRA]}
*{[DimAssessment].[Question Text].&[Do you use tobacco products?]}
*[DimPatient].[Patient Key].[Patient Key].members
*Generate(
[DimAssessment].[Answer Text].[Answer Text].MEMBERS
,[DimAssessment].[Answer Text].CURRENTMEMBER
*TAIL(
NonEmpty(
[DimDate].[Full Date Alternate Key].[Full Date Alternate Key].MEMBERS
,[DimAssessment].[Answer Text].CURRENTMEMBER
)
,1 //[DimAssessment].[Question Text].&[Do you use tobacco products?]
)
)
ON ROWS
FROM
[Care];
We will need to move more of the logic inside the generate.
First try the following to see if it returns two correct columns?
SELECT
[Measures].[Assessment Patients Detail] ON COLUMNS,
NON EMPTY
Generate(
[DimPatient].[Patient Key].[Patient Key].MEMBERS
,[DimPatient].[Patient Key].CURRENTMEMBER
*TAIL(
NonEmpty(
[DimDate].[Full Date Alternate Key].[Full Date Alternate Key].MEMBERS
,[DimPatient].[Patient Key].CURRENTMEMBER
)
,1
)
ON ROWS
FROM
[Care];

Related

MDX sort order in Crossjoin

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.

MDX query to order (and topfilter) results after/with a crossjoin

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];

How to get max value using MDX Query

I'm trying to get maximum value for Dimension table where the data as referred with Fact table
WITH
MEMBER [Measures].[Max key] AS
Max
(
[DimAnchorDate].[Date Key].MEMBERS
,[DimAnchorDate].[Date Key].CurrentMember.Member_Key
)
SELECT
{
[Measures].[Max key]
} ON COLUMNS
FROM X;
This query is giving me output : 20141231
In FactTable we have data upto 20141031. From the above query I would like to get 20141031
So now I am trying to get max value from DimAnchordate table as same as it is coming in FactPatientDr Table (i.e 20141031).So please suggest me the best way to achieve this...
I think at the moment you are looking at Dates that are empty in certain parts of the cube space - try forcing to nonempty by using a measure from the FactPatientDr
WITH
MEMBER [Measures].[Max key] AS
Max
(
nonempty(
[DimAnchorDate].[Date Key].MEMBERS
,[Measures].[SomeMeasureInFactPatientDr]
)
,[DimAnchorDate].[Date Key].CurrentMember.Member_Key
)
SELECT
{
[Measures].[Max key]
} ON COLUMNS
FROM X;
I think we can use Tail function to get desired result with measure value as well:
select non empty([Measures].[Entered Case],
tail
(Order
([Calendar].[Date].[Date].members
,[Measures].[Entered Case]
,basc
)
,1
)) on 0 from [SolutionPartner]

Union in MDX query

In my time dimensions i have 2013,2014,2015.
How can i make a Union in this mdx so i get the results from this mdx for all thoose years and not only for 2014 like in the example..
select NON EMPTY {[Measures].[Absatz Plan], [Measures].[Umsatz Plan], [Measures].[Absatz Effektiv], [Measures].[Umsatz Effektiv]} ON COLUMNS,
NON EMPTY Crossjoin(Hierarchize({([Time].[2014], [Artikel].[All Artikels], [Markt].[All Markts])}), {[Version].[14], [Version].[16], [Version].[18]}) ON ROWS
from [Budget]
Just apply CrossJoin twice:
select NON EMPTY
{[Measures].[Absatz Plan], [Measures].[Umsatz Plan], [Measures].[Absatz Effektiv], [Measures].[Umsatz Effektiv]}
ON COLUMNS,
NON EMPTY
CrossJoin(
Crossjoin(
{[Time].[2013], [Time].[2014], [Time].[2015]},
{([Artikel].[All Artikels], [Markt].[All Markts])}
),
{[Version].[14], [Version].[16], [Version].[18]}
)
ON ROWS
from [Budget]
I removed the Hierarchize, as I think it is not necessary in this context. It would order its argument by the order defined for the hierarchy in the cube. If the order of the result seems wrong, you could re-add it.

Getting a count of users each day in Mondrian MDX

I'm trying to write a query to give me the total number of users for each customer per day.
Here is what I have so far, which for each customer/day combination is giving the total number of user dimension entries without splitting them up by customer/day.
WITH MEMBER [Measures].[MyUserCount]
AS COUNT(Descendants([User].CurrentMember, [User].[User Name]), INCLUDEEMPTY)
SELECT
NON EMPTY CrossJoin([Date].[Date].Members, [Customer].[Customer Name].Members) ON ROWS,
{[Measures].[MyUserCount]} on COLUMNS
FROM
[Users]
The problem with your calculated member is that [User].CurrentMember is set to the All member for every row tuple, and thus the count is the total. What you need is a way for the [Customer].CurrentMember and [Date].CurrentMember to effectively filter the [User] dimension.
You need to use a measure that makes sense, i.e. that will have a non-empty value for meaningful joins of the dimension members that you're interested in.
To find this out, you could start by running a query like this:
SELECT
NON EMPTY CrossJoin(
[User].[User Name].Members,
[Measures].[Some measuse]
) ON COLUMNS,
NON EMPTY CrossJoin(
[Date].[Date].Members,
[Customer].[Customer Name].Members
) ON ROWS
FROM [Project]
You would have selected Some measure adequately. The results of that query will be a lot of empty cells, but in a given row, the columns that do have a value correspond to the Users that are related to a given Customer x Date tuple (on the row). You want to count those columns for every row. COUNT and FILTER are what you need, then the query with the calculated member will be
WITH MEMBER [Measures].[User count] AS
COUNT(
FILTER(
[User].[User Name].Members,
NOT ISEMPTY([Measures].[Some measure])
)
)
SELECT
NON EMPTY {[Measures].[User count]} ON COLUMNS,
NON EMPTY CrossJoin(
[Date].[Date].Members,
[Customer].[Customer Name].Members
) ON ROWS
FROM [Users]
I am assuming a fair bit here, but with some experimentation you should be able to work it out.