current member from a custom set - mdx

I'm trying to create a custom set and I wanna take the current member of this custom set that I created
WITH
SET [~SET] AS
Order(
[especialidade].[nome].Members,
[Measures].[consulta_valor],
DESC
)
MEMBER [Measures].[prev] AS
([especialidade].[id].CurrentMember.PREVMEMBER, [Measures].[consulta_valor])
SELECT {[Measures].[prev],[Measures].[consulta_valor]} ON 0,
[~SET] on 1
FROM [consulta]
My idea is when I'm creating that member use the set that I created to do my interaction, my goal is to see if the measure of the current member is equals to the previous member because I'll put a position in my members and the same values need to have same position.
Someone could help me please?

Try
[especialidade].[nome].currentmember
The set name is just an alias. You are still referencing the nome hierarchy.

Related

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'

Qlik sense ignore filters / selections

Using qlik sense
I have the following measure
RangeAvg(Below(Count( Distinct {1< Year=>} [OrderID]), 0, 52))
I still need when a user selects a year from the filer pane , the measure is unaffected
however using the Year= does not work
Any ideas team please?
The set identifier of 1 represents "the full set of all the records in the application, irrespective of any selections made." If you want all user selections to be accounted for except for Year, simply change the set identifier to $ (assuming you've not set up and used any other alternate states). The $ set identifier refers to the default state; the one that selections are made in by default when the user selects something in the interface.
If you want to ignore all filters but the year you can try this following code:
RangeAvg(Below(Count(Distinct{1<Year = p(Year)>} [OrderID]), 0, 52))
p function mean all possible values
For more information, you can read this help section from the Qlik site

How can I give a user the permission to create a field but not to change it?

I wanna a user to create a record but later dun give it the right to change the value of that field. should I do it By overriding create and write methods? is it possible to write such code:
field1: fields.float(string='Field',write=['base.GROUP_ID']),
This may work create a status field this field is a compute field when it's true the field1 will be read only. Because i'm on my phone i'm not going to writr the hole code just try to understand the idea
status = field.Boolean(compute='compute_status')
def compute_status(self):
for rec in self:
# first check of the use belong to the group that have full acces
if self.env.user.has_group('group_id') :
rec.status = False
# then check if the record is saved in databse
# unsaved records There id is instance of NewId it's a dummy class used for this
elif instanceOf(NewId ,rec.id) :
rec.status = False # here all users can fill the field when the record is not created yet but cannot edit
else :
rec.status = True # if record is saved and user is not in group_id make field readonly or invisible as you want
Now create your field and use status property to make it readonly when status field is True .
As you can see my answer is algorithme more than a code sorry for sysntax errors
I think the better way to do this is to create a group to which the user will belong, then set in the ir.model.access a rule, with the rights you want, for that particular group.
Ask if you need more help.
EDIT
You can define a view, that inherit from the original one, but is accessible only for the user group, like:
<field name="groups_id" eval="[(6, 0, [ref(' < your group > ')])]"/>
and there you redefine the field making it readonly. That's it.

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

Orientdb sql auto increment: id is always null (sql batch, update increment, variables)

I was looking at another question in stackoverflow regarding auto increment fields in orientdb, where one of the answers was to create our own vertex with counter field.
However, when I'm trying to execute the following code (both java api and console script batch), It is not working.
Do note however that the id is returned good (did some debug attempts, returning the id variable only), and the vertex is created.
However, the vertex id is always null (unless I set it explicit, that is).
The script:
script sql
LET id = UPDATE CCounter INCREMENT value=1 RETURN AFTER $current WHERE name='session'
LET csession = CREATE VERTEX CDate SET id=$id.result, meet_date='2015-01-01 15:23:00'
end
I tried playing around with $id and $current , but nothing seems to work.
Currently I am doing it in a 2-transaction mode; one to get the id, and another to create the vertex. I really hope there is a better way though.
P.S.
I am using version 2.0-M2
You should execute
LET csession = CREATE VERTEX CDate SET id=$id.value, meet_date='2015-01-01 15:23:00'
Note the $id.value in place of $id.result.
As stated in a comment to Lvca, the answer was:
(1) Change the field name. Id seems to be reserved (ish). It's probably possible to still bypass it and use a field named 'id', but I didn't want to mess around with it.
(2) From some reason, the result was a collection (shown as '[id]'). It took me some time to figure it out, but I just had to choose the first value from it.
(3) Also, there are 2 'values' here. One of the field ($current.value), and the second one(not sure where it's coming from).
Final solution that works:
script sql
LET id = UPDATE CCounter INCREMENT value = 1 RETURN AFTER $current.value WHERE name='session'
LET csession = CREATE VERTEX CDate SET data_id=$id[0].value, meet_date='2015-01-01 15:23:00'
end