I have written below query to get count of job numbers from a fact dimension. It is working fine.
WITH SET V_Lots AS
{[ABC Lots].[ABC Type].&[A]
,[ABC Lots].[ABC Type].&[O]}
*
{[ABC Lots].[ABC Load Nbr].[ABC Load Nbr]}
MEMBER
[MEASURES].[ABC_V_CNTRS]
AS
COUNT(V_Lots)
SELECT
{[MEASURES].[ABC_V_CNTRS]} ON COLUMNS
FROM
[ABC Model]
Now I have to save this in the cube, I tried to rewrite it as a calculated member but its returning null value. Please let me know if I am missing something here?
(COUNT([ABC Lots].[ABC Load Nbr].[ABC Load Nbr]),{[ABC Lots].[ABC Type].&[A]
,[ABC Lots].[ABC Type].&[O]})
Related
I have a column named Con_TYPE in which there are multiple types of connections such as fiberoptic, satellite, 3g etc.
And I want to sort them only into 2 rows:
fiberoptic
5
others
115
Can anybody help me?
Thanks in advance
You can use Calculated dimension or Mapping load
Lets imagine that the data, in its raw form, looks like this:
dimension: Con_TYPE
measure: Sum(value)
Calculated dimension
You can add expressions inside the dimension. If we have a simple if statement as an expression then the result is:
dimension: =if(Con_TYPE = 'fiberoptic', Con_TYPE, 'other')
measure: Sum(Value)
Mapping load
Mapping load is a script function so we'll have to change the script a bit:
// Define the mapping. In our case we want to map only one value:
// fiberoptic -> fiberoptic
// we just want "fiberoptic" to be shown the same "fiberoptic"
TypeMapping:
Mapping
Load * inline [
Old, New
fiberoptic, fiberoptic
];
RawData:
Load
Con_TYPE,
value,
// --> this is where the mapping is applied
// using the TypeMapping, defined above we are mapping the values
// in Con_TYPE field. The third parameter specifies what value
// should be given if the field value is not found in the
// mapping table. In our case we'll chose "Other"
ApplyMap('TypeMapping', Con_TYPE, 'Other') as Con_TYPE_Mapped
;
Load * inline [
Con_TYPE , value
fiberoptic, 10
satellite , 1
3g , 7
];
// No need to drop "TypeMapping" table since its defined with the
// "Mapping" prefix and Qlik will auto drop it at the end of the script
And we can use the new field Con_TYPE_Mapped in the ui. And the result is:
dimension: Con_TYPE_Mapped
measure: Sum(Value)
Pros/Cons
calculated dimension
+ easy to use
+ only UI change
- leads to performance issues on mid/large datasets
- have to be defined (copy/paste) per table/chart. Which might lead to complications if have to be changed across the whole app (it have to be changed in each object where defined)
mapping load
+ no performance issues (just another field)
+ the mapping table can be defined inline or loaded from an external source (excel, csv, db etc)
+ the new field can be used across the whole app and changing the values in the script will not require table/chart change
- requires reload if the mapping is changed
P.S. In both cases selecting Other in the tables will correctly filter the values and will show data only for 3g and satellite
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'
I'm consistently unable to store data into a QVD file. The syntax I've been using works perfectly in other applications, but for some reason I can't get it to work in the application I'm trying to finish.
I've successfully developed a data model, now need to loop through by years, reduce the data for just the specific years, and then save that out to individual QVD files.
Here's the code:
FOR i = $(vL.MinFY) TO $(vL.MaxFY)
LET _table = 'T_FACT_$(i)_GL_BALANCES';
[$(_table)]:
LOAD
*
RESIDENT [FINAL BALANCES]
WHERE LEFT([Year-Period],4) = $(i)
;
IF NoOfRows('$(_table)') > 0 THEN
STORE $(_table) INTO [$(vG.TransformQVDPath)$(_table).QVD];
END IF
LET vRowCount_$(i) = NoOfRows('$(_table)');
DROP TABLE [$(_table)];
NEXT
The script burps on the DROP TABLE statement, and nothing is saved to QVD. I've tried various combinations of dollar-sign expansion, with and without quotes, brackets, etc.
Hope someone can help me determine what I'm missing.
DOH! Figured it out.
The LOAD statement requires a NOCONCATENATE, or else each iteration of the table is simply concatenated with the source table. Updated script for the load section is:
[$(_table)]:
NOCONCATENATE LOAD
*
RESIDENT [FINAL BALANCES]
WHERE LEFT([Year-Period],4) = $(i)
;
After doing that everything worked as expected.
I have the following scenario:
I have my MDX code in a cell in a dimension.
e.g. [MDXCode].[Code].[Code] contains the string:
"([GL Account].[GL Account Code L1].&[ABC],[Measures].[Amount]) + ([GL Account].[GL Account Code L1].&[XYZ],[Measures].[Amount])"
Now I want this cell evaluated as MDX code.
I tried with StrToMember and ToTuple but do not get it working.
e.g.
StrToTuple([MDXCode].[Code].[Code])
However if I limit my example to ([GL Account].[GL Account Code L1].&[ABC],[Measures].[Amount]) it works. If I add another tuple to sum both it does not..
Try this:
StrToValue([MDXCode].[Code].CurrentMember.Name)
Edit upon further info. If you can make MDX Formula a property of Ratio Name:
StrToValue([Finance Ratio].[Ratio Name].CurrentMember.Properties("MDX Formula"))
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