I currently have the following code in MDX that I've been struggling on getting formatted in the way I need.
WITH
MEMBER measures.Quantity_Chicago_Madison AS
IIF([Tb Consumer].[City].currentmember is [Tb Consumer].[City].&
[Chicago] and [Tb Supplier].[City].currentmember is [Tb Supplier].[
City].&[Madison], [Measures].[Quantity - Tb Transactions], null)
MEMBER measures.Quantity_Madison_Chicago AS
IIF([Tb Consumer].[City].currentmember is [Tb Consumer].[City].&[Madison]
and [Tb Supplier].[City].currentmember is [Tb Supplier].[City].&[Chicago]
, [Measures].[Quantity - Tb Transactions], null)
SELECT non empty {
measures.Quantity_Madison_Chicago,measures.Quantity_Chicago_Madison
} ON COLUMNS, non empty
{ [Tb Product].[Name].[Name].ALLMEMBERs*[Tb Consumer].[City].allmembers*
[Tb
Supplier].[City].allmembers} ON ROWS
FROM [DS715]
I am getting the following output from running this query.
Current Output
Ideally, I want my output to be the following: Ideal Output
I feel like I've tried everything, but I know there's one piece of the puzzle that I can't quite figure out. Any help would be so great. Thank you
Please try below script:
WITH
MEMBER measures.Quantity_Chicago_Madison AS
([Tb Consumer].[City].&[Chicago] * [Tb Supplier].[City].&[Madison] , [Measures].[Quantity - Tb Transactions])
MEMBER measures.Quantity_Madison_Chicago AS
([Tb Consumer].[City].&[Madison] * [Tb Supplier].[City].&[Chicago] , [Measures].[Quantity - Tb Transactions])
SELECT non empty {
measures.Quantity_Madison_Chicago,measures.Quantity_Chicago_Madison
} ON COLUMNS, non empty
{ [Tb Product].[Name].[Name].ALLMEMBERs } ON ROWS
FROM [DS715]
Related
I am working with data in an OLAP-cube setup. I am wanting to display all Math Student Groups with the distinct student count for each group. Students get placed into a Math group based on how they scored on their math placement exam. They also get placed in every Math group lower than the one they placed into. (placed into Math 106, also a member of Math 105, 104, 103, 102, 101 and 100) Currently I am able to show only Math Groups on my rows and Distinct Students as a measure on the columns. The counts that display are only distinct per row and not for the entire report. So Math 100 group is displaying the count of all students in Math groups, not just Math 100.
WITH
/*- Qv6.0.3431.1887 -*/
SELECT
NON EMPTY
{
DISTINCT ( { [Measures].[Distinct Students] } )
}
PROPERTIES PARENT_UNIQUE_NAME, MEMBER_KEY, MEMBER_TYPE
ON COLUMNS,
NON EMPTY
{
{ [Student].[Student].[All Students] }
* { { { DISTINCT(
{ { FILTER(
{ { FILTER(
{ DESCENDANTS( [Student Group].[Student Group].[All Student Groups] , [Student Group].[Student Group].[Student Group]) } , InStr(1,IIF( ISERROR( [Student Group].[Student Group].CURRENTMEMBER.MEMBER_CAPTION ),"", [Student Group].[Student Group].CURRENTMEMBER.MEMBER_CAPTION ) , "Math") <> 0
) }
} , InStr(1,IIF( ISERROR( [Student Group].[Student Group].CURRENTMEMBER.MEMBER_CAPTION ),"", [Student Group].[Student Group].CURRENTMEMBER.MEMBER_CAPTION ) , "eligible") <> 0
) }
} ) }
} }
}
PROPERTIES PARENT_UNIQUE_NAME, MEMBER_KEY, MEMBER_TYPE
ON ROWS
FROM [Student Term]
WHERE ( [Terms].[Terms].[Term].&[138] )
CELL PROPERTIES FORMATTED_VALUE, VALUE, FONT_NAME
Here is a screenshot of the output:
Math Groups Student counts
I have tried searching all over here but was not successful in finding anything to help. I am by no means proficient in MDX, the reporting tool we use creates it based on what items we choose in the report builder (drag and drop mostly). The tool does allow you to create custom measures and elements using MDX. I really appreciate all assistance and please let me know if more information is needed.
Thanks!
====UPDATE 1-FEB-2017=======
thanks for your reply. I am finally getting to work on this again. I created custom measures in our front-end tool based on your code. I changed the [Measures].[StudentsCount] to [Measures].[Distinct Students] to match an available measure. If I select the 'StudentsCountDC' custom measure and run the report it returns nothing. If i select the 'IsStudentsTop' custom measure the counts it returns are extremely large like it isn't running for the selected term. Here is the new MDX that was generated after I ran the report with the newly created custom measure, 'StudentsCountDC'.
WITH
/*- Qv6.0.3431.1887 -*/
SELECT
NON EMPTY
{
DISTINCT ( { [Measures].[#~~2d0c2a98-fed9-4797-a573-170d3e450e4c~~#] } )
}
PROPERTIES PARENT_UNIQUE_NAME, MEMBER_KEY, MEMBER_TYPE
ON COLUMNS,
NON EMPTY
{
{ [Student].[Student].[All Students] }
* { [#~~9faf06d9-a022-493d-9dfd-dadd55793c37~~#] }
}
PROPERTIES PARENT_UNIQUE_NAME, MEMBER_KEY, MEMBER_TYPE
ON ROWS
FROM [Student Term]
WHERE ( [Terms].[Terms].[Term].&[136] )
CELL PROPERTIES FORMATTED_VALUE, VALUE, FONT_NAME
screenshots of new measures: IsStudentsTop & StudentsCountDC measures
Thanks again for your help!
It's a bit tricky, I personally haven't tested it yet. Hope, you'll get the point:
with
Member [Measures].[StudentsCountDC] as
SUM(
[Student].[Student].[Student].Members,
IIF(
not [Measures].[IsStudentsTop]
and
[Measures].[StudentsCount],
1,
NULL
)
)
Member [Measures].[IsStudentsTop] as
SUM(
{[Student Group].[Student Group].PrevMember:NULL},
[Measures].[StudentsCount]
)
IsStudentsTop checks whether StudentsCount exists in the upper groups (ordered by your attribute). StudentsCountDC checks if the current student has empty IsStudentsTop and StudentsCount is non empty, then returns 1 for each student, else returns Null.
I want to combine 3 queries like that in one query but I don't know how can I do this:
Query 1:
select {
Crossjoin({[Measures].[Store sales]}, {[Occupation].[Occupation].Members})
} on columns,
{
[Product].[Product Family].Members
} on rows
From test
Something like this is ok - but you need to bring All members into the script so that each set of tuples has the same dimensionality:
SELECT
[Measures].[Store sales]
*
{
[Occupation].[Occupation].MEMBERS * {[Essai].[All]}
,
{[Occupation].[All]} * [Essai].[Essai].MEMBERS
} ON COLUMNS
,{[Product].[Product Family].MEMBERS} ON ROWS
FROM test;
Sorry, the second query is
select {
Crossjoin({[Measures].[Store sales]}, {[Yearly_Income]. [Yearly_Income].Members})
} on columns,
{
[Product].[Product Family].Members
} on rows
From test
I am using sharepoint report builder.
In my data (se picture below) - I would like to get all the first row - the ones with yellow.
How do i do that.
Here is the MDX code. What should I write to get the yellow rows?
SELECT
NON EMPTY
{[Measures].[Antal unikke brugere - Visiteret Tid]} ON COLUMNS
,NON EMPTY
{
[Borger].[Anonym Borgernøgle DPR].[Anonym Borgernøgle DPR].ALLMEMBERS*
[SundhedOgOmsorg - Ydelse].[Ydelse].[Ydelse].ALLMEMBERS*
[Kalender].[År].[År].ALLMEMBERS*
[Kalender].[Måned].[Måned].ALLMEMBERS
}
DIMENSION PROPERTIES
MEMBER_CAPTION
,MEMBER_UNIQUE_NAME
ON ROWS
FROM
(
SELECT
{
[SundhedOgOmsorg - Ydelse].[Ydelse].&[12.1 Hjemmetrænerforløb]
,[SundhedOgOmsorg - Ydelse].[Ydelse].&[12.2 Komb. Hjemmetræner & Terapeutforløb]
,[SundhedOgOmsorg - Ydelse].[Ydelse].&[12.3 Komplekse Rehabiliteringsforløb]
,[SundhedOgOmsorg - Ydelse].[Ydelse].&[12.7. hverdagsrehab. revis.gr. m. tp.]
} ON COLUMNS
FROM
(
SELECT
{[SundhedOgOmsorg - Modul].[Modul].&[Hjemmehjælp]} ON COLUMNS
FROM [FrbLis]
)
)
WHERE
[SundhedOgOmsorg - Modul].[Modul].&[Hjemmehjælp]
CELL PROPERTIES
VALUE
,BACK_COLOR
,FORE_COLOR
,FORMATTED_VALUE
,FORMAT_STRING
,FONT_NAME
,FONT_SIZE
,FONT_FLAGS;
You could try using one of the following iterative mdx functions:
Generate - https://msdn.microsoft.com/en-us/library/ms145526.aspx
Filter - https://msdn.microsoft.com/en-us/library/ms146037.aspx
To use filter is a little more convoluted as you need to specify specific tuples based on their relative positions. Generate is a little more straightforward. I will try to provide an example against the MS AdvWrks cube.
I think this is relatively similar to your situation:
SELECT
{[Measures].[Internet Sales Amount]} ON 0
,NON EMPTY
[Product].[Product Categories].[Product]
*
{
[Date].[Calendar].[Date].&[20050801]
:
[Date].[Calendar].[Date].&[20050807]
} ON 1
FROM [Adventure Works];
You would like the rows I've marked in red (there are lots of products with only 1 row)
So if we now apply the following multi-dimensional expression to the cube:
WITH
SET [prodSet] AS
[Product].[Product Categories].[Product]
SET [prodDtSet] AS
Generate
(
[prodSet] AS P
,Head
(
P.Current
*
NonEmpty
(
{
[Date].[Calendar].[Date].&[20050801]
:
[Date].[Calendar].[Date].&[20050807]
}
,(
P.Current
,[Measures].[Internet Sales Amount]
)
)
)
)
SELECT
{[Measures].[Internet Sales Amount]} ON 0
,[prodDtSet] ON 1
FROM [Adventure Works];
We get the results required:
Are you able to adapt my example to your context?
I will have a further play and supply a solution using Filter (it'll be, in a way, a little more complicated than the Generate approach)
Here is an approach using Filter:
WITH
SET [prodSet] AS
[Product].[Product Categories].[Product]
SET [prodDtSet] AS
NonEmpty
(
[prodSet]
*
{
[Date].[Calendar].[Date].&[20050801]
:
[Date].[Calendar].[Date].&[20050807]
}
,[Measures].[Internet Sales Amount]
)
SET [prodDtSetFiltered] AS
Filter
(
[prodDtSet]
,
(NOT
[prodDtSet].Item(
[prodDtSet].CurrentOrdinal - 1).Item(0)
IS
[prodDtSet].Item(
[prodDtSet].CurrentOrdinal - 2).Item(0))
OR
[prodDtSet].CurrentOrdinal = 1
)
SELECT
{[Measures].[Internet Sales Amount]} ON 0
,[prodDtSetFiltered] ON 1
FROM [Adventure Works];
Results are as following:
I have some sort of difficulties trying to join 2 MDX queries together. When running them separately they work fine. The script below
WITH
MEMBER [Measures].[ParameterCaption] AS
[Main_Incidents].[Priority].CurrentMember.Member_Caption
MEMBER [Measures].[ParameterValue] AS
[Main_Incidents].[Priority].CurrentMember.UniqueName
MEMBER [Measures].[ParameterLevel] AS
[Main_Incidents].[Priority].CurrentMember.Level.Ordinal
SELECT
{
[Measures].[ParameterCaption]
,[Measures].[# Incidents]
,[Measures].[%SLA]
} ON COLUMNS
,[Main_Incidents].[Priority].ALLMEMBERS ON ROWS
FROM [Model];
WITH
MEMBER [Measures].[ParameterCaption] AS
[Main_Incidents].[usr_directorate].CurrentMember.Member_Caption
MEMBER [Measures].[ParameterValue] AS
[Main_Incidents].[usr_directorate].CurrentMember.UniqueName
MEMBER [Measures].[ParameterLevel] AS
[Main_Incidents].[usr_directorate].CurrentMember.Level.Ordinal
SELECT
{
[Measures].[ParameterCaption]
,[Measures].[# Incidents]
,[Measures].[%SLA]
} ON COLUMNS
,[Main_Incidents].[usr_directorate].ALLMEMBERS ON ROWS
FROM [Model];
The most important bit for me is that I need the label column to show. So I want to UNION the 2 queries together so that the ParameterCaption captures values from "Priority" dimension and "Directorate" dimension....
Please someone help me to achieve this?
This is a bit complex, but definitely possible.
Union in MDX only works for members of the same hierarchy, so to achieve this we need to make the row members into Tuples that combine the two hierarchies. We can do this by cross joining each of the ALLMEMBERS sets to the [All] member for the other hierarchy. Then we just need to change the Parameter Caption, Value and Level to conditionally get the value from the appropriate hierarchy.
This could look something like the code below:
WITH
MEMBER [Measures].[ParameterCaption] AS
IIF([Main_Incidents].[Priority].CurrentMember.Level.Ordinal = 0, [Main_Incidents].[usr_directorate].CurrentMember.Member_Caption, [Main_Incidents].[Priority].CurrentMember.Member_Caption)
MEMBER [Measures].[ParameterValue] AS
IIF([Main_Incidents].[Priority].CurrentMember.Level.Ordinal = 0, [Main_Incidents].[usr_directorate].CurrentMember.UniqueName, [Main_Incidents].[Priority].CurrentMember.UniqueName)
MEMBER [Measures].[ParameterLevel] AS
IIF([Main_Incidents].[Priority].CurrentMember.Level.Ordinal = 0, [Main_Incidents].[usr_directorate].CurrentMember.Level.Ordinal , [Main_Incidents].[Priority].CurrentMember.Level.Ordinal)
SELECT
{
[Measures].[ParameterCaption]
,[Measures].[# Incidents]
,[Measures].[%SLA]
} ON COLUMNS
,{
[Main_Incidents].[Priority].ALLMEMBERS * [Main_Incidents].[usr_directorate].[All],
[Main_Incidents].[Priority].[All] * [Main_Incidents].[usr_directorate].ALLMEMBERS
} ON ROWS
FROM [Model];
I have created an MDX query which calculates the TOP 10 ZipCodes (according to my Patient Stay measure) as such:
WITH
MEMBER [Discharge Date].[Y-M-D].[ Aggregation] AS 'AGGREGATE( EXISTING { [Current Month] } )', SOLVE_ORDER = 0
SELECT
NON EMPTY { [Measures].[Patient Stays] }
ON COLUMNS,
TOPCOUNT({ ORDER( HIERARCHIZE( { [Patient].[ByZipcode].[All].CHILDREN } ), ( [Measures].[Patient Stays] ), BDESC ) }, 10)
ON ROWS
FROM [Patient Stay]
WHERE ( [Discharge Date].[Y-M-D].[ Aggregation], [Facility].[ByAffiliation].CURRENTMEMBER, [Facility].[ByRegion].CURRENTMEMBER )
This query is used to populate a PerformancePoint 100% Stacked Bar chart. The client has asked that since this is a !00% based chart, we lump the rest of the zip codes into an "Other" field, such that there should be 11 values: one for each of the top 10, and an eleventh which is a sum of the remaining Zip Codes.
I am an extreme novice to MDX, but this doesn't souund like it should be impossible. Does anyone have any ideas or suggestions?
I'll do my best with untested code, so here goes:
WITH
MEMBER [Discharge Date].[Y-M-D].[ Aggregation] AS 'AGGREGATE( EXISTING { [Current Month] } )', SOLVE_ORDER = 0
SET [Top10ZipCodes] AS
(TOPCOUNT({ ORDER( HIERARCHIZE( { [Patient].[ByZipcode].[All].CHILDREN } ), ( [Measures].[Patient Stays] ), BDESC ) }, 10))
MEMBER [Patient].[ByZipCode].[OtherZipCodes] AS
(AGGREGATE({EXCEPT([Patient].[ByZipCode].Members, [Patient].[ByZipCode].[Top10ZipCodes])}))
SELECT
NON EMPTY { [Measures].[Patient Stays] }
ON COLUMNS,
{[Top10ZipCodes], [Patient].[ByZipCode].[OtherZipCodes]}
ON ROWS
FROM [Patient Stay]
WHERE ( [Discharge Date].[Y-M-D].[ Aggregation], [Facility].[ByAffiliation].CURRENTMEMBER, [Facility].[ByRegion].CURRENTMEMBER )
What this does is creates a set of your top 10 ZIP codes, and then aggregates (different than sum!!!) all the ZIP codes, with the exception of your top 10.
Also, if this is a common set (top 10 ZIP codes), you may want to make a set on the cube, where you can reuse it ad nauseum, without having to change every MDX query you have.
Cheers,
Eric