Using events in Drilldown (mdxExpression) - mdx

When I try to use events in a mdxExpression drilldown strategy I get an MDX evaluation internal error: The measure [Measures].[#{sort_by!revenue}] does not exist:
CASE $member.hierarchy.name
WHEN [TOP_LIST_DIMENSION].[TOP_LIST_ID].name THEN
TopCount([PRODUCT_DIMENSION].[PRODUCTS].members, 10, [Measures].[#{sort_by!revenue}])
ELSE ic3drilldownStop()
END
If I replace [Measures].[#{sort_by!revenue}] with [Measures].[revenue] it works as expected, but then I can't change the measure to sort by.

Related

QlikSense Expression Displaying only Previous Month's Values

I have started working with QS recently and I have a problem with defining an expression which will allow me to display previous month's data.
I have tried creating previous month variable:
vPreviousMonth = MonthName(Addmonths(Max([Calendar Termination Month]),-1))
however this did not work - retrieves value 0. Then I tried below:
If(MonthStart([Calendar Termination Month])=MonthStart(Today()),-1,0) as PreviousMonth which doesn't work either - retrieves current month's values, used in below expression:
sum({<PreviousMonth={"-1"}>} [Terminated]).
Lastly, I tried
sum({$<[Calendar Termination Month]={"$(=[Calendar Termination Month](AddMonths(Max(Date),-1),'YYYY-MM'))"}>}[Terminated])
which, surprise!, retrieved 0 value as well.
Is there any way I can somehow make this work?
Try this
sum({$<[Calendar Termination Month]={"$(=month(AddMonths([Termination Date],-1))))"}>}[Terminated])

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.

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

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'

Apache Solr sort based on score and fieldn values

I used the following request
http://localhost:8983/solr/test6/select?q=*:*&sort=product(score,hits)%20desc
to sort results based on their relevancy score as determined by Apache Solr multiplied by a field called hits (integers).
However, I receive the following error message:
{ "responseHeader":{
"status":400,
"QTime":0,
"params":{
"q":"*:*",
"sort":"product(score,hits) desc"}}, "error":{
"metadata":[
"error-class","org.apache.solr.common.SolrException",
"root-error-class","org.apache.solr.common.SolrException"],
"msg":"sort param could not be parsed as a query, and is not a field that exists in the index: product(score,hits)",
"code":400}}
Why is it that sort cannot correctly input the function value when:
http://localhost:8983/solr/test6/select?q=*:*&sort=score%20desc
http://localhost:8983/solr/test6/select?q=*:*&sort=hits%20desc
work when a function isn't applied?
NOTE: http://localhost:8983/solr/test6/select?q=*:*&sort=product(hits,2)%20desc where I added the product() function also returns the same error message.
The score value isn't really a field - so you can't use a function to manipulate it in the sort clause.
Instead you can use a multiplicative boost through boost (if you're using edismax) to achieve what you want: &boost=hits. You might want to use log(hits) or something similar (recip for example) instead to avoid large differences in score for just small changes in the number of hits.

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