The Axis0 function expects a tuple set expression for the argument - ssas

I just want to get the invoices distinct count of sales on March. I got this MDX query.
My MDX Query:
select
distinctcount([Measures].[Sales #]) on columns,
--[Measures].[Sales #] on columns,
non empty ([Customer].[Store Group].[Store Group]) on rows
from
(
select
{
[Calendar].[Month].[March 2015]
}
ON columns
from [F1_SalesBI])
But I got the following error, whenever I tried executing this.
Executing the query ...
The Axis0 function expects a tuple set expression for the argument. A string or numeric expression was used.
Execution complete

Here is the definition from msdn:
https://msdn.microsoft.com/en-us/library/ms145519.aspx
Syntax:
DistinctCount(Set_Expression)
You're doing this when you use Measures as the argument:
DistinctCount(Numeric_Expression)
Something like the following should hopefully run ok:
WITH
SET [mySet] AS
[Customer].[Store Group].[Store Group] * {[Measures].[Sales #]}
MEMBER [Measures].[setDistCount] AS
DistinctCount([mySet])
SELECT
{
[Measures].[setDistCount]
,[Measures].[Sales #]
} ON 0
,NON EMPTY
[Customer].[Store Group].[Store Group] ON 1
FROM
(
SELECT
{[Calendar].[Month].[March 2015]} ON 0
FROM [F1_SalesBI]
);
To return the number of invoices for the month try the following:
WITH
SET [mySet] AS
{[Calendar].[Month].[March 2015]} * {[Measures].[Sales #]}
MEMBER [Measures].[setDistCount] AS
DistinctCount([mySet])
SELECT
{
[Measures].[setDistCount]
} ON 0
FROM [F1_SalesBI];
If the above returns 1 then try inspecting the set via this script:
SELECT
{} on 0,
{[Calendar].[Month].[March 2015]} * {[Measures].[Sales #]} ON 0
FROM [F1_SalesBI];
Does this just return 1 member?
How about this (without the set braces around the measure)?:
SELECT
{} on 0,
{[Calendar].[Month].[March 2015]} * [Measures].[Sales #] ON 0
FROM [F1_SalesBI];

Related

How to insert a string literal as a new column in an mdx query

In the following MDX query, I want to set the value of [Measures].[Label] as the string literal "Net Value" instead of NULL (i.e. using a string literal to populate the values in the label column). I'm scratching my head about how to do this in MDX. Tons of background with SQL, but a relative newbie with SSAS.
`WITH
Member [Measures].[Label] AS NULL
Member [Measures].[Value] AS [Measures].[Net Amt]
SELECT NON EMPTY
(
{[Time].[Quarter].[Quarter]},
{[Time].[Month].[Month]},
{[Time].[Work Week].[Work Week]},
{[Customer].[Region Cd].[Region Cd]},
{[Product].[Cd Nm].[Cd Nm]}
) ON Rows,
NON EMPTY
(
{
[Measures].[Value],
[Measures].[Label]
}
) ON Columns
FROM [Reporting]
WHERE
(
{
[Time].[Year].[Year].&[2022]:[Time].[Year].[Year].&[2023]
},
{[Segment].[Segment Nm].[Segment Nm].&[SEG VALUE]}
)`
If I try a value in double quotes, the query just times out without finishing. Just using a null like this only takes 2 seconds to return.
Member [Measures].[Label] AS "Net Amt"
The problem with putting a constant is that the NON EMPTY now returns every combination of Time, Customer and Product.
Instead you want to return a constant but only on rows where the Net Amt measure is not empty.
Member [Measures].[Label] AS IIF(Not(IsEmpty([Measures].[Net Amt])),"Net Amt",Null)
Alternately you could use a constant but use the NonEmpty function instead against the Net Amt measure only:
Member [Measures].[Label] AS "Net Amt"
Member [Measures].[Value] AS [Measures].[Net Amt]
SELECT NonEmpty(
{
{[Time].[Quarter].[Quarter]}*
{[Time].[Month].[Month]}*
{[Time].[Work Week].[Work Week]}*
{[Customer].[Region Cd].[Region Cd]}*
{[Product].[Cd Nm].[Cd Nm]}
},
[Measures].[Net Amt]
) ON Rows,
{
[Measures].[Value],
[Measures].[Label]
}
ON Columns

Mondrain MDX for records between date range where start and end date being separate columns

I want to search date between two columns of same dimension. Columns name is start date and end date. I tried every thing, following query give me this error : Mondrian Error:Internal error: Cannot deduce type of call to function ':'
MDX query :
WITH
SET [~ROWS] AS
Hierarchize
(
{
{[Location_Cluster.default].[All Location_Cluster.defaults]}
,{[Location_Cluster.default].[Location_Cluster].MEMBERS}
}
)
MEMBER [Measures].[QTY Percent] AS
[Measures].[Total_Quantity]
/
(
[Measures].[Total_Quantity]
,[Location_Cluster.default].[All Location_Cluster.defaults]
)
,format_string = '0.00%'
MEMBER [Measures].[Revenue Percent] AS
[Measures].[Total_Revenue]
/
(
[Measures].[Total_Revenue]
,[Location_Cluster.default].[All Location_Cluster.defaults]
)
,format_string = '0.00%'
MEMBER [Measures].[Margin Percent] AS
[Measures].[Total_Margin]
/
(
[Measures].[Total_Margin]
,[Location_Cluster.default].[All Location_Cluster.defaults]
)
,format_string = '0.00%'
SELECT
NON EMPTY
{
[Measures].[Sku_Count]
,[Measures].[Total_Quantity]
,[Measures].[QTY Percent]
,[Measures].[Total_Revenue]
,[Measures].[Revenue Percent]
,[Measures].[Total_Margin]
,[Measures].[Margin Percent]
} ON COLUMNS
,NON EMPTY
[~ROWS] ON ROWS
FROM [APCS_SALES_CUBE]
WHERE
(
{[Date].[Start_Date].&[2017-01-01] : NULL}
,{NULL : [Date].[End_Date].&[2017-03-01]}
,[Cluster.Cluster_Id].[2]
,[Taxonomy.default].[Taxonomy_ID].[3]
,[Company.Company_Name].[Compnay_Name].[1]
);
I followed following links to resolve this issue. But don't know how to apply specify function in Mondrian MDX
https://ask.sqlservercentral.com/questions/95478/mdx-for-records-between-date-range-where-start-and.html#answer-142811
https://www.purplefrogsystems.com/blog/2013/04/mdx-between-start-date-and-end-date/#comment-1981
Your query is not well formed. You need to make set out of the range you want to slice. Here is an example:
WITH SET [~ROWS] AS
(${dateFromParameter} : ${dateToParameter})
MEMBER Measures.[number] as
FORMAT([date].[godina].CurrentMember.PROPERTIES("datum"), "dd.mm.yyyy")
SET [ROOT] AS
FILTER([ORG].[org_id].Members, [ORG].[org_id].currentmember.parent.parent=[ORG].[org_id].currentmember.parent)
SELECT
NON EMPTY {[Measures].[total], Measures.[number]} ON COLUMNS,
NON EMPTY [ROOT] * [~ROWS] ON ROWS
FROM [svcs]

MDX currentMember get me error

This MDX function raise error :
with member measures.x as
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].currentmember.value
,
[Measures].[current balance]
)
select measures.x on columns,
[Branch].[HeadOffice Branch].[Head Office Code] on rows
from MyCube
Error is :
The CURRENTMEMBER function expects a hierarchy expression for the 1 argument. A member expression was used.
But when I use
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].&[20160131]
It works good
why?
This is valid mdx:
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
Although this is not:
WITH member measures.x AS
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
It is not valid because round braces (...) signify a tuple but a tuple requires exact co-ordinates so the first argument cannot be a set.
You could add an aggregation such as SUM:
WITH member measures.x AS
SUM
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
This is valid mdx but if you do not have [Date].[Date] in context i.e. in the WHERE or SELECT clause then all it is returning is the All member.
Why are you using [Date].[Date].currentmember ?
CURRENTMEMBER works on an attribute hierarchy (in your case [Date].[Date]). So [Date].[Date].CURRENTMEMBER will work.
Also you will need to take out the value selector, as your expression returns a set of dates (member : member returns a set of all the members between those two members).

Mdx Query Show Year Level Data for all years except This Year

SELECT
NON EMPTY
{[Measures].[AMOUNTCUR]} ON 0
,NON EMPTY
{
NULL : [PRX_UE_DATE].[Calender].[Year].&[2015]
,[PRX_UE_DATE].[Calender].[Year].&[2017]
,Descendants
(
[PRX_UE_DATE].[Calender].[Year].&[2016]
,[PRX_UE_DATE].[Calender].[Month]
)
} ON 1
FROM [PRX_SalesDataModel];
I have a query like above. It's working It returns 2016 on month based others years are year based.
Now I have to add more dimensions on this mdx but when i try it to like
SELECT
NON EMPTY
{[Measures].[AMOUNTCUR]} ON 0
,NON EMPTY
{
NULL : [PRX_UE_DATE].[Calender].[Year].&[2015]
,[PRX_UE_DATE].[Calender].[Year].&[2017]
,
Descendants
(
[PRX_UE_DATE].[Calender].[Year].&[2016]
,[PRX_UE_DATE].[Calender].[Month]
)
*
[PRX UE CLIENT].[SEGMENTID].ALLMEMBERS
} ON 1
FROM [PRX_SalesDataModel];
I get error Members, tuples or sets must use the same hierarchies in the function.
You just need to keep all the date dimension stuff in set braces {...}:
SELECT
NON EMPTY
{[Measures].[AMOUNTCUR]} ON 0
,NON EMPTY
{
NULL : [PRX_UE_DATE].[Calender].[Year].&[2015]
,[PRX_UE_DATE].[Calender].[Year].&[2017]
,
Descendants
(
[PRX_UE_DATE].[Calender].[Year].&[2016]
,[PRX_UE_DATE].[Calender].[Month]
)
}
* [PRX UE CLIENT].[SEGMENTID].ALLMEMBERS
ON 1
FROM [PRX_SalesDataModel];
You could even make it maybe more readable by moving the date stuff into a named set via a WITH clause:
WITH SET [DatesSet] AS
{
NULL : [PRX_UE_DATE].[Calender].[Year].&[2015]
,[PRX_UE_DATE].[Calender].[Year].&[2017]
,
Descendants
(
[PRX_UE_DATE].[Calender].[Year].&[2016]
,[PRX_UE_DATE].[Calender].[Month]
)
}
SELECT
NON EMPTY
{[Measures].[AMOUNTCUR]} ON 0
,NON EMPTY
[DatesSet]
* [PRX UE CLIENT].[SEGMENTID].ALLMEMBERS
ON 1
FROM [PRX_SalesDataModel];
You've got your answer from #whytheq on why the error cropped up. There is just one part which I felt is not handled yet. You are building the set of years by hand. Instead of that, it can be made dynamic like below -
with set AllYearsExceptCurrent as
filter(
[PRX_UE_DATE].[Calender].[Year].members as yr,
yr.current.item(0).member_value <> Format(Now(), "yyyy")
)

MDX multiple EXCEPT filter in calculated member

I have following query for calculated member:
SUM(
EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])
, [Measures].[CountPolicyEndorsesNull]
)
What I want is to include another EXCLUDE filter. I have tried following:
SUM(
{EXCEPT([Policy].[Policy Status].[Policy Status],[Policy].[Policy Status].&[Void])}
*
{EXCEPT([Invoice].[Invoice Status].[Invoice Status],[Invoice].[Invoice Status].&[Void])}
, [Measures].[CountPolicyEndorsesNull]
)
but it returns more result than the first query. Any ideas?
Your syntax is correct. The reasons it could be more are the following:
You have negative results in ([Invoice].[Invoice Status].&[Void], [Measures].[CountPolicyEndorsesNull])
You have a default member set on [Invoice].[Invoice Status].[Invoice Status].
Try returning the following query:
select
[Measures].[CountPolicyEndorsesNull]
on columns,
{[Invoice].[Invoice Status].DefaultMember,
[Invoice].[Invoice Status].&[Void]
}
on rows
from [CubeName]
That will get you your culprit.