Mdx, greater than works like String and not Numeric (Saiku) - mdx

I am using Saiku and trying to filter by mdx, using the symbol '> (greater than)', in the default Sales cube. The problem is that's it filtering like String and not Numeric. The values that I want for the query below is [51,52], but the server olap response is [6,7,8,9,51,52]. Any idea how can I filter that?
Here's the query:
WITH
SET [~ROWS] AS
{
FILTER([Time].[Weekly].[Week].Members, [Time].[Weekly]. [Week].CurrentMember.Properties("Caption") > '50')
}
SELECT
NON EMPTY {[Measures].[Unit Sales]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [Sales]

The response is to use 'Cint', like bellow:
WITH
SET [~ROWS] AS
{
FILTER([Time].[Weekly].[Week].Members, Cint([Time].[Weekly].[Week].CurrentMember.Properties("Caption")) > 50)
}
SELECT
NON EMPTY {[Measures].[Unit Sales]} ON COLUMNS,
NON EMPTY [~ROWS] ON ROWS
FROM [Sales]

I think there may be alternative approaches. With experimenting as some may be more efficient.
WITH MEMBER Measures.ValueColumn as [Date].[Calendar].[July 1, 2001].MemberValue
MEMBER Measures.KeyColumn as [Date].[Calendar].[July 1, 2001].Member_Key
MEMBER Measures.NameColumn as [Date].[Calendar].[July 1, 2001].Member_Name
SELECT {Measures.ValueColumn, Measures.KeyColumn, Measures.NameColumn} ON 0
from [Adventure Works]

Related

How to code a where clause into a calculated member?

The first query works as I needed. But when I tried to rewrite in terms of a calculated member to put it in my cube, It crashed.
select non empty [Measures].[Demanda Real] on 0,
non empty [Agente Distribuidor].[Nombre Distribuidor].[Nombre Distribuidor].members on 1
from Demanda
where [SkSubmercadoUsuario]
First MDX query results
This is my failed try:
with member [Measures].[Demanda Real Dos]
as
([Measures].[Demanda Real], [SkSubmercadoUsuario])
select [Measures].[Demanda Real Dos] on 0,
non empty [Agente Distribuidor].[Nombre Distribuidor].[Nombre Distribuidor].members on 1
from Demanda
What I need is slice my cube by [SkSubmercadoUsuario], but it cannot be by a where clause. I need to create a measure that slices the measure by this Named Set [SkSubmercadoUsuario]
May be you need to do something like this
with member [Measures].[Demanda Real Dos]
as
SUM({[Sk Submercado Usuario].&[52], [Sk Submercado Usuario].&[622]},
[Measures].[Demanda Real] )
select [Measures].[Demanda Real Dos] on 0,
non empty [Agente Distribuidor].[Nombre Distribuidor].[Nombre Distribuidor].members on 1
from Demanda
I'm not sure to understand what you're trying to do.
Do you just want to create a second measure [Measures].[Demanda Real] renamed as [Measures].[Demanda Real Dos] in your query or do you want to create your measure in the "calculation script part" of your cube ?
In the first case, I think you don't need to move the condition part. Try this :
with member [Measures].[Demanda Real Dos]
as
([Measures].[Demanda Real])
select [Measures].[Demanda Real Dos] on 0,
non empty [Agente Distribuidor].[Nombre Distribuidor].[Nombre Distribuidor].members on 1
from Demanda
where [SkSubmercadoUsuario]

format_string in icCube does not format null values

I was trying to display values that are null as 0 using format_string.
I currently have the following:
WITH
MEMBER [test] AS null, FORMAT_STRING = '0.#;Neg (0.#);0.00;0.00'
SELECT
[test] ON COLUMNS
FROM [Sales]
The fourth value (;0.00) should format the null values to zeros. I read that here: https://msdn.microsoft.com/en-us/library/ms146084.aspx
Currently it shows nothing. It should show 0.00.
You can try it here: http://www.iccube.com/run-mdx
It is a bug (ic3pub_159) that is going to be fixed in the next version. As a workaround you can use the coalesceEmpty MDX function.
CoalesceEmpty( [MyValue] , 0.0 )

Custom Column header in MDX

I am trying to fill MDX query result to a datatable. Query is generating dynamically. When i fill datatable column header like [Dim Date].[Day].[Day]. I need it Log Date.
Is there any way to change column header ? I mean, in TSQL we using
select firstName [User] from users
Is there any way to achieve this ?
Thanks in advance
You can do this on the SQL side like this:
WITH mdx as (
<your MDX query>
)
SELECT [[Dim Date]].[Day]].[Day]]] as [Log Date]
...
FROM mdx
The escaping rules of square brackets make this a bit strange: You have to double all closing square brackets.
You can get this slightly more easy, avoiding the square bracket quoting in the rename action by using
WITH mdx([Log Date], ...) as (
<your MDX query>
)
SELECT [Log Date], ...
FROM mdx
enumerating the desired column names after the CTE name "mdx".

How to correctly use InStr with ActivePivot?

I am trying to use the INSTR() function with ActivePivot. I am testing by using an Instr call that should always return > 0.
Here is my initial MDX query that works fine:
SELECT
{
{[CODE].[ALL].[AllMember]}
} ON ROWS
FROM [Cube]
WHERE ([Measures].[contributors.COUNT])
Here is my test InStr query:
SELECT
NON EMPTY
Generate
(
[CODE].[ALL].[AllMember]
,(
Instr
(
"Test"
,"es"
) > 0
)
)ON ROWS
FROM [Cube]
WHERE ([Measures].[contributors.COUNT])
Please can you help me create a working example for the Instr MDX query in ActivePivot?
Many thanks
Edit: What I wanted to do
SELECT
NON EMPTY Hierarchize({[CODE].[CODE].Members}) ON ROWS,
NON EMPTY Hierarchize({Filter([RELEVANCE].Members, InStr([RELEVANCE].CurrentMember.Name, "n/a") > 0)}) ON COLUMNS
FROM [Cube]
WHERE ([Measures].[contributors.COUNT])
I'm not sure about what you try to achieve with your MDX but here is an example which may be helpful:
Before, I consider all places with a positive contributors.COUNT:
SELECT
NON EMPTY Hierarchize({Filter([PlaceDimension].[Continent].Members, [Measures].[contributors.COUNT] > 0)}) ON ROWS
FROM [TwitterCube]
WHERE ([Measures].[contributors.COUNT])
After, I keep only places with an "a" in their name:
SELECT
NON EMPTY Hierarchize({Filter([PlaceDimension].[Continent].Members, InStr([PlaceDimension].CurrentMember.Name, "a") > 0)}) ON ROWS
FROM [TwitterCube]
WHERE ([Measures].[contributors.COUNT])

SQL-Doesn't return a value when the columns are multiplied

I have 3 columns in my db table, I need to multiply column, itm_count & itm_price and output the total for a given id(itm_id).
SELECT sum(itm_price * itm_count) as total FROM ods_temporder WHERE itm_id='11'
I tried to do this using the above sql query, but the result was null. What seems to be the issue here?
What do this give you?
SELECT itm_price, itm_count FROM ods_temporder WHERE itm_id='11'
Is either of itm_price or itm_count NULL? Do you have rows for itm_id = 11?
Try:
SELECT SUM(COALESCE(itm_price, 0) * COALESCE(itm_count, 0)) as total
FROM ods_temporder
WHERE itm_id='11'
COALESCE is an ANSI standard for dealing with NULL values - if itm_price or itm_count is null, zero will be used in this case as the value. Otherwise, either you don't have a row with a value of 11 for the itm_id column, or you're looking for the 11 value in the wrong column.
What does itm_price and itm_count contain when itm_id= 11?
Is this SQL Server? If so you can use ISNULL to handle whether itm_price or itm_count is null