I have Action URL which will open web site from excel. I need to pass names of all employee which are currently listed in excel to that web site. This list is coming from cube and could be filter by user using many different measures.
But after all there would available some [Employee].[Name].
So my question is how can I generate string with all employees names from current members .
Below MDX how such list of employees could be receive from cube:
SELECT NON EMPTY {[Measures].[Salary]} ON COLUMNS,
NON EMPTY {[Employee].[Name]} ON ROW
FROM [Cube]
WHERE (
[Employee].[Department].[X],
[Employee].[Title].[Z]
…
…
)
List of dimension in clause WHERE is unknown – it will depend what user will used in excel
Let assume that this MDX would return 5 names:
A
B
C
D
E
What I need to get for each row is the list all of this employees but only those currently display. So in above example the result should look like:
A A,B,C,D,E
B A,B,C,D,E
C A,B,C,D,E
D A,B,C,D,E
E A,B,C,D,E
So then I could pass this in URL to web site
I’ve tried to do this using GENERATE with and without EXISTING but the result was that I either get list all employees from cube (not currently selected) or only one.
Can someone please help me with this?
You'll need a calculated member and us the generate mdx function (doc). The first idea would be :
MEMBER [Measures].[ListAsName] AS Generate( [Employee].[Name].members, [Employee].[Name].currentmember.name, ", ")
The problem with this is that [Employee].[Name].members it's not filtered by the where clause (as it's the case with the axis). This is due to the fact it's in a calculated member context.
You've two possible solutions :
Use EXISTING. This implies we are certain that all members in the slicer are members of [Employee] dimension:
MEMBER [Measures].[ListAsName] AS Generate( Existing [Employee].[Name].members, [Employee].[Name].currentmember.name, ", ")
Use non empty:
MEMBER [Measures].[ListAsName] AS Generate( nonempty([Employee].[Name].members), [Employee].[Name].currentmember.name, ", ")
use both :-) -> nonempty( EXISTING [Employee].[Name].members )
The fact the first one is not working is or a bug of SSAS or a problem in your MDX query. The second one is a bit heavy but should work too. The third one is the bullet proof version.
Related
I am relatively new to MDX, about a month or so, and I am now writing MDX queries against a remote cube I also work on (Java 8 ActivePivot).
This query works when they are ORs, but when I add parentheses and change that first OR to an AND it works, kind of, but drops the measure resulting in the CDR and BOOK dimensions coming back correctly. Can someone with more MDX knowledge tell me what I have missed or do not yet know?
WITH
Member [Measures].[CDR_Label] AS [CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY
{[Measures].[CDR_Label],
[Measures].[Book_Label],[Measures].[RepoRate.LATEST]}
ON COLUMNS,
NON EMPTY
FILTER(
([CDR].CHILDREN,[Book].CHILDREN), (LEFT([CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION,1) = "8") AND
(LEFT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,2) = "ST" OR
RIGHT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,4) = "CIES"))
ON ROWS
FROM [TraderCube]
WHERE ([Date].[Date].[2019-10-23])
And here the query before I changed it, with OR OR etc which works. I wanted the above to return only the CDR beginning with 8, which it does, but it loses the measure (and also breaks my headers - as this is actually being fired from inside an xll / custom Excel function, to a dll calling the remote cube using AdomdClient package as I am building a very custom plugin - Essentially the ability for users to use simple words/from enumerations presented and I then translate and construct MDX in C# to fire at the cube. Data comes back and I send 2D arrays back to Excel :)).
WITH
Member [Measures].[CDR_Label] AS [CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION SELECT NON EMPTY {[Measures].[CDR_Label],[Measures].[Book_Label],[Measures].[RepoRate.LATEST]}
ON COLUMNS,
NON EMPTY
FILTER(
([CDR].CHILDREN,[Book].CHILDREN),
LEFT([CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION,1) = "8" OR
LEFT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,2) = "ST" OR
RIGHT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,4) = "CIES")
ON ROWS
FROM [TraderCube]
WHERE ([Date].[Date].[2019-10-23])
Aah...ignore me!
I think I was tired and didn't see the pattern. Essentially, and I just reproduced this, if you ask for two dimension patterns that do exist with a measure, you get back the dimensions you expect (in my case 3, a real measure and two fake / labels for the dimensions to bring them all back as rows).
If there are no matches it seems to return you back what you asked for without any measures as they do not exist for the dimension combination.
I am trying to write an MDX query to return some information about survey questions. I want Average response and total responses in my results. I have two types of questions. One type of question has a single response. Another type of question can have multiple responses (Pick all that apply). Each question is tied to a question ID and a respondent ID. The following query works (somewhat)
Select NON EMPTY
{
[Measures].[Average Response], [Measures].[Total Count]
} ON 0
, NON EMPTY
{
([Question].[Question ID].[Question ID].ALLMEMBERS)
} ON 1
From [Cube]
Average Response is a combination from both single responses and multiple responses (two different fact tables). The total count is also a combination of the two tables. The problem is that for single response questions, I can just count the number of respondents. For multi response questions that falls down as I can have way more responses than I do people taking the survey. I really want to know how many people provided an answer. To do this, I think I need the distinct count of respondent IDs. So I tried changing my first axis to this.
[Measures].[Average Response], [Measures].[Total Count], DISTINCTCOUNT([Respondent].[Respondent ID])
Well, that doesn't work and I really didn't expect it to. I got "The function expects a tuple set expression for the 3 argument. A string or numeric expression was used." which is rapidly becoming my favorite SSAS error message. I am still green at this and I guess I am still thinking SQL. How can I get an average of the responses and a count of the distinct Dimension values in the same query. BTW, my query does have a slicer and I could provide that if needed but I don't think it relevant as I get the same problems with or without the slicer.
When working with the MDX DistinctCount function, it returns the count of distinct, non-empty tuples of a given set of data. Perhaps try doing something like
DistinctCount({[Respondent].[Respondent ID].members * [Measures].[Total Count]})
so that way you are working with a set (e.g. {...}) of data.
If you're working with a larger set of data, you may want to consider creating a Distinct Count measure. The DistinctCount function itself is a SSAS Formula Engine query while using the Distinct Count measure would allow Analysis Services to use both the Storage Engine and Formula Engine. For more information, please refer to Analysis Services Distinct Count Optimization.
Let me start by saying, I have scoured the web for help with this, tried figuring it out with a professor and used a Database Systems text book and have still not gotten this to work properly. I am attempting to finish this database as my final project for a DB management course that I'm taking, but it is also for real world use at work. My team at work currently creates access to a clinical system for end users. When we receive a request form it includes a "ServiceNow Position" (Column A) and a "ServiceNow Role" (Column B). My team has to then reference a spreadsheet, which I've attempted to attach, to find out what this correlates to in the clinical system (Column C). The row of the spreadsheet also dictates what, if any, user orgs (Column F) and user groups (column G) that the user account receives. I'm including a screenshot of the relationship between the tables prior to my modifications to the SQL statement, as once the outer joins are in place, the relationships don't illustrate.
The idea here is that I will always be given the ServiceNow role and position, it will always correlate to a row on the "Cerner_HNA_Positions" table. I will NOT necessarily always have User_Group or Organizations, though when I do have them, I may have up to 2 and 4 respectively.
My goal is to get a query that works properly, and then create a form on top of this so that who ever is working account creations can insert the ServiceNow Position and Role and have returned what the "Cerner_HNA_Positions.HNA_Position" is and any correlated User Groups and Organizations. The following is the closest SQL statement that I've gotten to function without a syntax error. However, this is returning every HNA_User_Group and HNA_Org, even though the row for HNA_Position that it returns does not have any HNA_User_Group's or Orgs assigned. I'm sure this is something to do with the fact that I've done a left join, but my goal in this was to ensure that I see the HNA_Position. Can anyone help me with this?
SELECT DISTINCT Cerner_HNA_Positions.HNA_Position,
Cerner_HNA_Positions.Like_User,
Cerner_HNA_Positions.Physician,
Cerner_HNA_Positions.Add_Resources,
Cerner_HNA_User_Groups.*,
Cerner_HNA_Organizations.*,
[Service Now Position Name].Service_Now_Position,
[ServiceNow Role].Service_Now_Role
FROM Cerner_HNA_User_Groups,
Cerner_HNA_Organizations,
[ServiceNow Role]
INNER JOIN ([Service Now Position Name]
INNER JOIN Cerner_HNA_Positions
ON [Service Now Position Name].Service_Now_Position_ID =
Cerner_HNA_Positions.Service_Now_Position_ID)
ON [ServiceNow Role].Service_Now_Role_ID =
Cerner_HNA_Positions.Service_Now_Role_ID
WHERE ((([Service Now Position Name].Service_Now_Position)="CIS - PowerChart")
AND (([ServiceNow Role].Service_Now_Role)="Resident"));
Spreadsheet referenced above: https://www.dropbox.com/s/1vreampypo17lcd/Positions_Roles%20Sheet.xlsx?dl=0
I have created a set to filter out the entire date dimension to it's respective measure:
CREATE SET DatesAvailable AS NonEmpty
([Date].[Hierarchy].[Day].MEMBERS, Measures.CURRENTMEMBER);
I would like for the filter to be applied automatically when using the date dimension in the cube browser. I've tried this but it returns a error related to the LastNonEmpty aggregate.
SCOPE(
UNION(
MEASUREGROUPMEASURES('MeasurerpG1')
, MEASUREGROUPMEASURES('MeasureGrp2')
, MEASUREGROUPMEASURES('MeasureGrp3')
) );
[Date].[Hierarchy].[Day].MEMBERS = DatesAvailable ;
END SCOPE;
How can I apply my set to filter the date dimension?
I do not think you can filter which members are shown in member lists, as presumably these list are not fetched via MDX, but via metadata lookups like the MDSCHEMA_MEMBERS schema rowset. You can more or less only change values in the calculation script which are then used in MDX statements. And you can add calculated members, which do then also appear in the metadata.
The only option I see to not display certain members in general tools where you do not have control how the tool generates the list of members that it shows would be by setting permissions.
I have a cube with some dimensions. There I have a dimension 'Product' which has some attributes and user defined hierarchies hidden. I do not know which attributes are hidden.
Is there a way to write an MDX to get the invisible attributes and user defined hierarchies?
I can get the name by other ways. But I want to know the way to get using MDX.
http://msdn.microsoft.com/en-us/library/ms145613.aspx gives an example query that reveals a member property:
WITH MEMBER [Measures].[Product List Price] AS
[Product].[Product].CurrentMember.Properties("List Price")
SELECT
[Measures].[Product List Price] on COLUMNS,
[Product].[Product].MEMBERS ON Rows
FROM [Adventure Works]
I cannot test it myself right now, but I assume that you could also write .Properties(0) or .Properties(1) to refer to properties by index, since you don't know the names. I'm not sure if there is a way to then discover the property name from the resulting cellset or not, sorry.
I'd start with looking into the DMVs for this, as you're really after metadata, not data.
http://dwbi1.wordpress.com/2010/01/01/ssas-dmv-dynamic-management-view/
They look like SQL, but run in the MDX window of SQL Management Studio, so will also run in an MSOLAP connection.
SELECT * FROM $system.mdschema_properties
That looks to be the query, a full list of members and a column identifying which are visible.
See how that works out for you.