SSAS Tabular incorrect syntax but it is correct - ssas

I am trying to use the IN function is analysis services tabular, but it is returning me an error. I tried the same on my co-worker's machine and it is working perfectly. I have already uninstalled my data tools 2017 and 2015 and installed again. Now I have only SSDT 2015 and having this problem.
TestMeasureIN:=
CALCULATE(
COUNTROWS(DimDate),
DimDate[MonthName] IN {"may", "july"}
)
SEMANTIC ERROR: THE SYNTAX FOR 'IN' IS INCORRECT

The IN function won't be available for versions of SSAS prior to 2017, so SSDT 2015 won't have this. You can rewrite this using CONTAINS as follows. Also, I'm guessing that TestMeasureIN is in your fact table as opposed to DimDate? If so, change COUNTROWS to the fact table to count the rows for the given months.
TestMeasureIN:=
CALCULATE (
COUNTROWS ( FactTableName),
FILTER (
ALL ( DimDate[MonthName]),
CONTAINS (
DATATABLE ( "MonthName", STRING, { { "may", "july"} } ),
[MonthName], DimDate[MonthName]
)
)
)

Related

How To Get All Items Created or Still Open For A Given Time

I am working with a system were items are created (postDate dimension) and closed (endDate dimension). The endDate column is always populated with the last time the item was seen. An item is considered closed in a certain time if its last seen date is before the date you are querying. Each row in the fact table has the item, postDate, endDate, locationID, and some other dimensions used for aggregations. What I am trying to accomplish is getting all items still active for a given time frame. For example I want to know all items posted in November 2008 or before November 2008 that has not yet closed. In SQL it would look something like:
SELECT C.geoCountyArea,TM.CalendarYear,COUNT(DISTINCT a.itemid)
FROM [dbo].[factTable] a
JOIN dbo.dimDate AS TM
ON TM.DateKey BETWEEN postDate AND endDate
JOIN [dbo].[dim_geography] C
ON A.geographyID=C.geographyID
WHERE C.geoCountyArea = '1204000057'
AND TM.CalendarYear = 2008 AND TM.MonthNumberOfYear = 11
GROUP BY C.geoCountyArea,TM.CalendarYear
ORDER BY C.geoCountyArea,TM.CalendarYear
This returns 27,715 which is expected. Now, in MDX this looks like:
WITH MEMBER Measures.[itemCount] AS
AGGREGATE(
{NULL:[PostDate].[Month Name].&[2008]&[11]} * {[EndDate].[Month Name].&[2008]&[11]:NULL},
[Measures].[Fact_itemCount]
)
SELECT NON EMPTY (
Measures.[itemCount]
) ON 0,
NON EMPTY (
{[PostDate].[Month Name].&[2008]&[11]},
{[Geography].[Geo County Area].&[1204000057]}
)ON 1
FROM [Cube];
This returns 27,717 - which is 2 more than the SQL version that could be due to items with no end Date posted. Now, the complication comes when I want to get more than one explicit time - for example item count for all months in 2008 or item count for all years. I looked up methods to link a given param to another one via roll playing dimensions and came across this link. I altered my script so it looks like:
WITH MEMBER Measures.[itemCount] AS
AGGREGATE(
{NULL:LINKMEMBER([DATE].[Calendar].CURRENTMEMBER
,[PostDate].[Calendar])}
* {LINKMEMBER([DATE].[Calendar].CURRENTMEMBER
, [EndDate].[Calendar]):NULL}
, [Measures].[Fact_itemCount]
)
SELECT {Measures.[jobCount]} ON 0,
NON EMPTY (
{[DATE].[Month Name].&[2008]&[11]},
{[Geography].[Geo County Area].&[1204000057]}
)ON 1
FROM [Cube];
This, however, returns only the items created in November 2008 - value of 14,884. If I add in other months I do get individual counts for each month but, again, these are just the items created in those months.
How do I get the "active" item count for a given month/year/quarter without having do explicitly declare the time values in the AGGREGATE?
Can you use NonEmpty?
WITH MEMBER Measures.[itemCount] AS
AGGREGATE(
{NULL:
NONEMPTY(
[PostDate].[Month Name].MEMBERS //<<AMEND TO EXACT STRUCTURE USED IN YOUR CUBE
,[DATE].[Calendar].CURRENTMEMBER
).ITEM(0).ITEM(0)}
* {NONEMPTY(
[EndDate].[Month Name].MEMBERS //<<AMEND TO EXACT STRUCTURE USED IN YOUR CUBE
,[DATE].[Calendar].CURRENTMEMBER
).ITEM(0).ITEM(0): NULL}
, [Measures].[Fact_itemCount]
)
...
This ended up being the solution that provided valid results (tested against SQL calls against the warehouse tables):
WITH MEMBER Measures.[itemCount] AS
AGGREGATE(
{NULL:LINKMEMBER([Post Date].[Calendar],
[Post Date].[Calendar])}
* {LINKMEMBER([Post Date].[Calendar],
[End Date].[Calendar]):NULL},
[Measures].[Fact_itemCount]
)
SELECT {Measures.[itemCount]} ON 0,
NON EMPTY (
{[Post Date].[Month Name].Children},
{[Geography].[Geo County Area].&[1204000057]}
)
FROM [Cube]
Not that I am doing LINKMEMBER against the post and end dates - not against the global Date measure.

drill down on reversed hierarchy gives incorrect results

I have got the following MDX statement in icCube (based on the standard Sales model):
with
set [time-set] as hierarchize({[Time].[Calendar].[All Periods],[Time].[Calendar].[Year].members,[Time].[Calendar].[Year].[2009].children},post)
member [issue] as [amount], caption = "drill down on 2008"
select [issue] on 0
, [time-set] on 1
from sales
This gives the following result:
When clicked on 2008:
I assume the IDE is a bit mixed up since I have used the POST command. Is there a workaround to get it working as expected?
Short answer.
Sorry, the current version of iccube's pivot table is not supporting the post flag.

MDX sum a previous month

I have created a cube with many different aggregations and any summing I do is within MDX. I am modeling lottery behavior based on previous drawings. Here is my current code:
WITH
SET [Alpha And Beta And Theta] AS
NONEMPTY (
{ [Dwtbl Dim Test Alpha].[Alpha PK].MEMBERS } *
{ [Dwtbl Dim Beta].[Beta PK].MEMBERS } *
{ [Dwtbl Dim Theta].[Theta PK].MEMBERS }
)
MEMBER Measures.TotalHits AS
SUM ( [Alpha And Beta And Theta]
, COALESCEEMPTY([Measures].[Hits],0)
)
MEMBER [Measures].[PrevMonth_TotalHits] AS
(ParallelPeriod ([Date].[CalendarYear].[Month NK]
, 1
, [Date].[CalendarYear].Currentmember
)
,[Measures].[TotalHits]
)
SELECT
{
[Measures].[TotalHits],
[Measures].[PrevMonth_TotalHits]
} ON COLUMNS
FROM [cubAgents]
WHERE ( [Date].[Year].[2013],
[Date].[Month NK].[7])
Now, when I pass in July, the code works as expected; I get hit counts from July and June. However, when I pass in August [8] which has not occurred yet, I get null for both current and previous month.
Why does this happen? Well, my set [Alpha And Beta And Theta] is a big nonempty crossjoin, with each dimension not occurring since it is in the future. If I remove the nonempty, it will work just fine ... but take 3 minutes to complete. I have spent too much time on this and I guess it is time to reach out to the experts.
Perhaps one method would be to directly sum my [Hits] measures for a previous month as opposed to using parallelPeriod, something like
MEMBER [Measures].[PrevMonth_Hits] AS
SUM ( {[Alpha And Beta And Theta]*[Date].[CalendarYear].Currentmember.LAG(1)}
, COALESCEEMPTY([Measures].[Hits],0)
)
This doesn't work.
Any help is greatly appreciated. Thanks!

MDX ignoring Excel filter

I'm just starting to get my head around MDX and I'm having trouble with a calculated member. I'm using the following MDX:
IIF(
ISEMPTY((Axis(1).Item(0).Item(0).Dimension.CurrentMember, [Measures].[Qty]))
,NULL
,([Product].[Product Code].CurrentMember.Parent, [Measures].[Qty])
)
What I'm trying to do is get a total quantity of the group of products displayed in a cube. I then use that total to divide by each product's quantity to get a "percent of total" measure. The above MDX does correctly return the total quantity of products displayed in any dimension. However, when a user in Excel changes the filter on which products are displayed, the MDX above still displays the total quantity for the whole group, ignoring which products the user has checked. I assume I'm lacking some basic understanding of MDX, how do I get the calculated measure to account for the product codes the user has selected in Excel?
With Visual Studio SQL Server Data Tools (if you are using that tool), you can browse to your cube, select the Calculations tab, and under Calculations Tools > Templates there is a template "Percentage of Total". The MDX this tool provides is flexible so that the percentage adjusts with the attributes of the hierarchy you've pulled into the pivot.
Case
// Test to avoid division by zero.
When IsEmpty
(
[Measures].[<<Target Measure>>]
)
Then Null
Else ( [<<Target Dimension>>].[<<Target Hierarchy>>].CurrentMember,
[Measures].[<<Target Measure>>] )
/
(
// The Root function returns the (All) value for the target dimension.
Root
(
[<<Target Dimension>>]
),
[Measures].[<<Target Measure>>]
)
End
I found this option to work when developing to achieve what you've mentioned.

MDX to SSAS calculation

I have written a MDX query which works fine in SQL Server Management Studio. My query is as follows:
SELECT [Measures].[Item Count]
ON 0
FROM [Inventory]
where [DateDiscontinued].[Date].[Discontinued Cal Year].&[0].&[0]
This query gives me all the items which are Discontinues.Now the problem is that when I copy paste the query in BIDS(SSAS Cube Calculation) as a calculated Member I get an error. It says it can't read the select statement. Do I need to write different MDX to support SSAS Calculated member or different function which supports SSAS Calculated Memeber?
The create member right syntax is:
CREATE [ SESSION ] [HIDDDEN] [ CALCULATED ] MEMBER CURRENTCUBE | Cube_Name.Member_Name
AS MDX_Expression
[,Property_Name = Property_Value, ...n]
......[,SCOPE_ISOLATION = CUBE]
Then ,your create member should be like:
CREATE MEMBER CURRENTCUBE.Measures.MyMeasure AS
([Measures].[Item Count] ,
[DateDiscontinued].[Date].[Discontinued Cal Year].&[0].&[0])