SSAS MDX: Calculated member doesn't show up in Excel - ssas

I created the calculated member as described below in SSMS (not VS, therefore I did not deploy it) by selecting the command and executing it. Accessing this member in MDX works out fine.
But Excel doesn't show me this measure, and I also do not see it in the cube browser. I expect to find it below the measure groups.
Question: What did I miss?
Additional question: How can I place this measure in a measure group?
CREATE MEMBER [Logistics].[Measures].[Printed] AS
SUM
(
{
(
[Pick].[Pick Method].&[4]
, EXCEPT([Pick].[Pick Type].MEMBERS, [Pick].[Pick Type].&[A])
, EXCEPT([Loc].[Build Zone].MEMBERS, {[Loc].[Build Zone].[All], [Loc].[Build Zone].&[G1], [Loc].[Build Zone].&[G2], [Loc].[Build Zone].&[G3]})
, EXCEPT([Loc].[Loc Code].MEMBERS, {[Loc].[Loc Code].[All], [Loc].[Loc Code].[EXPRESS]})
)
}
, [Measures].[Nb of Pick lines]
) ;
Executing this using this MDX-SELECT works out fine and returns a sensible result:
SELECT
NON EMPTY
{
[Location].[Build Zone].MEMBERS, [Location].[Build].[Tested]
} ON COLUMNS
, NON EMPTY {[Calendar].[Calendar Year].[Month].&[2019]&[August].children} ON ROWS
FROM [Logistics] ;

In SSMS you can only create Session-scoped calculated members, as described here
And what you did is that you successfully created this member, and in the same query window if you run this query:
select measures.allmembers on 0
from [Logistics]
you will actually see [Measures].[Printed] member. But as soon as you open a New Query window in SSMS on this cube, and run select measures.allmembers on 0 from [Logistics] again, you will not see your calculated member anymore.
So, the solution is to add this create member script in the Calculation Script in Visual Studio, as you mentioned, and to deploy the cube.
Additionally, to place a measure in measure group, or in some folder under it you can use ASSOCIATED_MEASURE_GROUP and DISPLAY_FOLDER properties. So something like this:
create member [MyCube].Measures.MyMeasure as 999, ASSOCIATED_MEASURE_GROUP = 'My measure group', DISPLAY_FOLDER = 'My display folder'

Related

error in google datastudio on using custom query

I am using a simple sql block of statements to execute and return a set of results in big query, This is working fine in big query and getting the results,I need to export this data to data studio, so in data studio i use bigquery as connector and select the project and custom query and in that I paste the contents below:
Declare metricType String;
SET metricType="compute.googleapis.com/instance/cpu/utilization";
BEGIN
IF (metricType="compute.googleapis.com/instance/cpu/usage_time")
THEN
SELECT m.value as InstanceName,metric.type as metricType,point.value.double_value as usagetime,point.interval.start_time as StartTime,point.interval.end_time as EndTime,h.value as instance_id FROM `myproject.metric_export.sd_metrics_export_fin`, unnest(resource.labels) as h,unnest(metric.labels) as m where metric.type='compute.googleapis.com/instance/cpu/usage_time' and h.key="project_id";
ELSE IF (metricType="compute.googleapis.com/instance/cpu/utilization")
THEN
SELECT m.value as InstanceName,metric.type as metricType,point.value.double_value as utilizationrate,point.interval.start_time as
StartTime,point.interval.end_time as EndTime,h.value as instance_id FROM `myproject-.metric_export.sd_metrics_export_fin`,unnest(resource.labels) as h,unnest(metric.labels) as m where metric.type='compute.googleapis.com/instance/cpu/utilization' and h.key="project_id";
END IF;
END IF;
END;
but after click "ADD" button i get the below error:
I am not sure what is this error about? I have not used any stored procedure and I am just pasting it as custom query.
Also If I try to save the results of the BigQuery into a view from the Bigquery console results pane, it gives me the error,
Syntax error: Unexpected keyword DECLARE at [1:1]
I am extremely new to datastudio and also to bigquery. Kindly Help thanks
First, I would like to make some considerations about your query. You are using Scripting in order to declare and create a loop within your query. However, since you declare and set the metricsType in the beginning of the query, it will never enter in the first IF. This happens because the value is set and it is not looping through anything.
I would suggest you to use CASE WHEN instead, as below:
SELECT m.value as InstanceName,metric.type as metricType,
CASE WHEN metric.type = #parameter THEN point.value.double_value ELSE 0 END AS usagetime,
CASE WHEN metric.type = #parameter THEN point.value.double_value ELSE 0 END AS utilizationrate,
point.interval.start_time as StartTime,point.interval.end_time as EndTime,h.value as instance_id
FROM `myproject.metric_export.sd_metrics_export_fin`, unnest(resource.labels) as h,unnest(metric.labels) as m
WHERE metric.type=#parameter and h.key="project_id";
Notice that I am using the concept of Parameterized queries. Also, for this reason this query won't work in the console. In addition, pay attention that whem you set the #parameter to "compute.googleapis.com/instance/cpu/utilization", it will have a non-null column with the usagetime and a null column named utilizationrate.
Secondly, in order to add a new data source in DataStudio, you can follow this tutorial from the documentation. After, selecting New Report, click on the BigQuery Connector > Custom Query> Write your Project id, you need to click in ADD PARAMETER (below the query editor). In the above query, I would add:
Name: parameter
Display name: parameter
Data type: text
Default value: leave it in blank
Check the box Allow "parameter" to be modified in reports. This means you will be able to use this parameter as a filter and modify its value within the reports.
Following all the steps above, the data source will be added smoothly.
Lastly, I must point that if your query ran in the Console you are able to save it as a view by clicking on Save view, such as described here.

MDX query works but ignores the EXCEPT clause

I have been working on a custom dll (that is called via a custom xll / Excel Addin) to construct MDX and return 2D data.
It's working nicely and I just went to work out how I add the ability to send in an exclusion list using EXCEPT.
I built up a query with filtering and this query works except it ignores the EXCEPT. Anyone with more MDX than me (I'm about 2 months in haha :)) know why?
Thanks
Leigh
WITH
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
Member [Measures].[Isin_Label] AS [Isin].[Isin].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY
{[Measures].[Book_Label],[Measures].[Isin_Label],[Measures].[Notional.SUM]}
ON COLUMNS,
NON EMPTY ORDER
(
EXCEPT(
FILTER(
([Book].CHILDREN,[Isin].CHILDREN),
([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION = "ALGO1")
),
[Isin].[Isin].[DE0001104776]),
[Notional.SUM]
,
BASC)
ON ROWS
FROM[TraderCube]
WHERE ([Date].[Date].[2019-11-18])
That is nice progress in two months. A humble piece of advise, you should always specify your problem in simple words along with the code developed so far. That helps the person answering.
Form your code, my understanding is you want "ALGO1" books with all members of [ISin] except the member "DE0001104776". Based on this understanding use the code below
NON EMPTY
ORDER
(
([Book].[Book].[ALGO1],{[Isin].[Isin].children-[Isin].[Isin].[DE0001104776]}),
[Notional.SUM],
BASC
)
I returned to trying out combining my currently working 1..n FILTER builder in conjunction with an EXCEPT (requested by business). Unfortunately, despite the query passing syntax check and executing, as reported in original post the cube/server ignores it.
I just tried adding a <> to my FILTER and it worked! :)
Here's an example.
WITH
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
Member [Measures].[Isin_Label] AS [Isin].[Isin].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY {[Measures].[Book_Label],[Measures].[Isin_Label],[Measures].[Notional.SUM]}
ON COLUMNS,
NON EMPTY
ORDER(
FILTER(
([Book].CHILDREN,[Isin].CHILDREN),
(([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION = \"ALGO1\") AND
([Isin].[Isin].CURRENTMEMBER.MEMBER_CAPTION <> \"DE0001102309\"))
),[Notional.SUM],
BASC)
ON ROWS
FROM[TraderCube]
WHERE([Date].[Date].[2019-11-21])

DAX: How to implement CREATE MEMBER MDX function in SSAS Tabular Model

I have a task to convert existing MDX measures (from multidimensional model) into DAX (tabular model). During this task I found that in DAX there is no functionality to use "CREATE MEMBER" option as it was in MDX. But I have some members created inside this cube by this function (not in DWH). In this case I'm trying to figure out how to do the same (equivalent) in tabular model (DAX)
There is a part of code which I'm replacing right now:
CREATE MEMBER CURRENTCUBE.[Condition].[Condition].[All].[NEW+USED]
AS [Condition].[Condition Type].[NEW]+[Condition].[Condition Type].[USED]
Image:
There is an example of [Condition] table from DWH:
I have an idea to create a VIEW based on this table with UNION to add a new row "NEW+USED" inside this VIEW and than use SWITCH inside cube (DAX function) for ALL measures
For example:
NVC:=
VAR GALC = [ABC] + [CDE]
RETURN SWITCH(
SELECTEDVALUE('Condition'[ConditionTotal]);
"ConditionTotal"; GALC;
"NEW+USED"; CALCULATE(
GALC;
FILTER(ALL('Condition'[ConditionDescription]); 'Condition'[ConditionDescription] = "New" && 'Condition'[ConditionDescription] = "Used")
)
)
But I'm not sure if it is correct way or not because in this case I should populate all columns from table and some of them using in relationships to Fact tables inside cube.
The only one good solution which I found for now in general looks like this:
Create a new database object (VIEW, for example) in your database with full list of recurred members (so the members will be created on database side instead of SSAS).
Create measure and add additional logic for these members inside your measure.
For example of measure:
My_measure:=
VAR New_var = CALC(SUM('FactTable'[Price]), 'Condition'[ConditionDescription] = "New")
VAR Used_var = CALC(SUM('FactTable'[Price]), 'Condition'[ConditionDescription] = "Used")
VAR New_and_Used_var = CALC(SUM('FactTable'[Price]), ALL('Condition'), 'Condition'[ConditionDescription] in {"New","Used"})
RETURN
SWITCH (SELECTEDVALUE('Condition'[ConditionDescription]),
"New", New_var,
"Used",Used_var,
"New + Used", New_and_Used_var
)
The only one thing which I additionally did is I make reference between my "FactTable" and this new database object (View) as INACTIVE (unchecked "Active" flag in reference window) because it worked not correctly with this flag.

creation of a set on measures raises an error in icCube

In schema Sales, I create a set which gives result if it is defined within the scope of a statement. The following code is in the MDX IDE:
with set [facts] as {[Measures].[Amount], [Measures].[Count]}
select [facts] on 0
from sales
This gives the measures Amount and Count perfectly as result
If I define the same set on the session level, or in the Builder (tab: advanced) it raises an error.
To reproduce, do the following in the MDX iDE:
create static set [facts-2] as {[Measures].[Amount], [Measures].[Count]}
and then type:
select [facts-2] on 0
from sales
The MDX IDE gives as error:
set( [facts-2] ) : '[Measures].[Amount]' is neither a dimension nor a
hierarchy within the cube.
Am I doing something illegal here or is this a bug?
You need to add the cube when creating the set. In this particular scenario is not usefull, but it's needed when there is an evaluation to define the evaluation scope.
So :
create static set [sales].[facts-2] as {[Measures].[Amount], [Measures].[Count]}
Yes, error is not very helpfull

Filtered Access 2010 Report Shows All Results

I have a report based in Access 2010 that prints information on a project. There are two subreports: one that lists all the projects under the criteria searched for, and one that actually prints the information. When I search for one project, the second subreports only prints the one, but the first lists all the projects.
Basically, I need to filter this SQL so that it only lists the projects under the project number (ProjNo) searched for. I'm not very good at SQL so any assistance would be appreciated.
SELECT Index.ProjNo, Index.Year, Index.Route, Index.Area, Index.[Value], Index.[Costs], Index.Page, Val(Nz([route],0)) AS routeNum
FROM [Index];
EDIT: I also need it to show all the projects when the user doesn't search for a specific one.
The WHERE clause should filter your report. Try changing "your search" to the appropriate value in your application.
SELECT Index.ProjNo
, Index.Year
, Index.Route
, Index.Area
, Index.[Value]
, Index.[Costs]
, Index.Page
, Val(Nz([toute],0)) AS routeNum
FROM [Index]
WHERE (((Index.ProjNo) = your search));