Simple grid from SSAS cube using MDX command - ssas

is there a better way to display simple grid (looking basically like SQL select statement) from SSAS cube using MDX command instead of using this Drillhrough workaround?
Here is what I've been using so far:
DRILLTHROUGH
Select
([Measures].[Some Measure]) on columns
From (
Select
{
[PeriodSpan].&[201301] : [PeriodSpan].&[201304]
}
on columns
From [CubeName]
)
RETURN
[$Dimension1].[Attribute1],[$Dimension1].[Attribute2],[$Dimension1].[Attribute3],[$Dimension1].[Attribute4],[$Dimension1].[Attribute5],
[$Dimension2].[Attribute1],[$Dimension2].[Attribute2],[$Dimension2].[Attribute3],
[$Dimension3].[Attribute1],[$Dimension3].[Attribute2],[$Dimension3].[Attribute3],[$Dimension3].[Attribute4],
IIF([Dimension4].[Attribute1]=[Dimension4].[Attribute1].&[False],[Dimension4].[Attribute2],[Dimension4].[Attribute3])
Problem is that now I can't figure out how to get IFF condition to work. When I try to run the command error message appears saying "Too many arguments were passed to the IIF MDX function. No more than 1 arguments are allowed." I also tried to create new member on cube level by calculation script:
SCOPE (some hierarchy here which I'm still not clear on how to use);
IF [$Dimension4].[Attribute1] IS [$Dimension4].[Attribute1].&[False] THEN this = [Dimension4].[Attribute2] END IF;
IF [$Dimension4].[Attribute1] IS [$Dimension4].[Attribute1].&[True] THEN this = [Dimension4].[Attribute3] END IF;
END SCOPE
I also tried calculated member and named set but with no results.
I'm fairly new to SSAS and MDX but I hope you see what I'm trying to accomplish. Thanks in advance. Any help would be much appreciated.

Related

Cannot view the SQL portion of a query in ACCESS?

I am currently working on a project of replacing our old access database queries, but on one of them I am not able to view the actual SQL View.
Does anyone know a way to force the view or to export it somehow?
Error causing problem:
The SQL statement could not be executed because it contains ambiguous outer joins.
Note that I can view the Design View without issue but when I right click on the tab and select SQL View is when I get the error.
I did attempt what #LeeMac mentioned below but same error occurs:
EDIT:
This question is not like Ambiguous Outer Joins?
The OP on that question can actually see and edit their SQL.
My issues is that I cannot see or edit the SQL as the SQL View wont open.
Try executing the following VBA code from the Immediate Window (accessible using Ctrl+G) in the VBA IDE (open the IDE using Alt+F11):
?CurrentDb.QueryDefs("YourQuery").SQL
Replace YourQuery with the name of your query.
This should print the SQL code which comprises your query - you can then analyse the SQL to determine the cause of the error.
It's odd this error would arise when merely viewing the SQL content of the query definition.
It makes me think that the query is perhaps referencing a crosstab subquery which is actually the cause of the error, but which needs to be evaluated in order for MS Access to determine the columns available when viewing the design of the query in question.
Try this:
hit ctrl-g, and from immediate window type in this:
saveastext acQuery,"Name of query","c:\test\mysql.txt"
Access ordinarily doesn't allow you to save invalid queries, so it's strange you somehow got into this situation in the first place.
If you can copy the query, you can easily get to the SQL by changing the query to a passthrough query, either through the GUI or through VBA:
Dim q As DAO.QueryDef
Set q = CurrentDb.QueryDefs!Query1
q.Connect = "ODBC;"
Debug.Print q.SQL
Passthrough queries are not validated, so you can freely read and write anything you want as SQL in it.
Note that this is irreversible when done through VBA. You can only change it back to a normal query once you made the SQL valid again. If you do it through the GUI, you can just not save it, though.
I had this problem and the issue was that i had a subquery that calculated fields but did not actually have a table in it. for example it would calculate first and last day of last month which is 2 calculated fields, then it was the first query in a series of queries that were built off it and the last one wouldnt resolve sql as original poster indicated also gave the ambiguous join message as well as query needs input table (which was that first subquery). i put a table with 1 record in it but didnt use the record and it worked.... so it just a needs a table in it.

Finding which function cause the error message while processing a table

by processing (Process Full,Process Data) a table (every table) in my cube, I get the following error:
Failed to save modifications to the server. Error returned: 'A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
The credentials provided for the SQL source are invalid. (Source at XXXX;XXXX.). The exception was raised by the IDbCommand interface.
How can I find which function cause this error?
Query the $SYSTEM.MDSCHEMA_MEASURES DMV, which lists measures in a Tabular model. The Expression column contains the definition of each measure, and you can use this to find any measures that have the MAX function that was specified in the error message. SSAS DMVs can either be queried from an MDX query editor window in SSMS or another tool such as Dax Studio. Dax Studio contains a listing of DMVs, and if you don’t already use it I’d recommend looking into this. You here find more information on this here. You can also execute your
measure in Dax Studio, which can help with
debugging it. You will also want to verify that the account you’re using has the proper permissions on the SQL Server objects used by your Tabular model.

SQL Vertica on Tableau: row_number over partition by multiple fields error

I have a query that uses
row_number() over(partition by a,b)
When I run the query in dbvisualizer, it runs fine. When I try to use it as a custom SQL query in Tableau, it throws the error:
Error 3537: Incorrect number of parameters for prepared statement _PLAN000011EBDD67590_42
Any idea what I should do? I need my data partitioned by both a and b but Tableau just isn't happy with it.
It's very probably not the ROW_NUMBER() function that perplexes Tableau.
"Incorrect number of parameters" usually means that you have a different number of parameter markers in a query that contains for example WHERE purchase_date = ?, and you maybe try to pass two values in a filter of your report.
I would check for the query that Tableau wants to send in detail, and look at the filter you are using to find inconsistencies .

how to use common function in query expression?

I want to use the "split" function in a simple query on my SSRS 2008 report. However, I get an error "Query execution failed for dataset "SlsmRealNum". "Split" is not a recognized built-in function name". But it's listed as a common function (text) if I open up the Expression box on the query, so not sure why it's failing?
my simple select statement is:
select slsm_num, slsm_msid from Salesman where slsm_msid = split(User.UserID,"\").GetValue(1)
right now to get the report to work, I have one parameter (SlsmnNum) that has the Split expression in it (to get the MSID of the user) and then a 2nd parameter that uses the above query in the Dataset Salesrepum using the #SlsmnNum parameter as the MSID. I'd like to not have to have 2 parapmeters if possible and just get the actualy salesrep # in just one. Any help is greatly appreciated!
Your select statement is executed as SQL so the error you are getting is actually from SQL server. This may be where you are getting confused.
There are two components to SSRS - SQL Statements and Report Expressions. Typically, SQL statements are used to generate datasets by querying the database. Report expressions are used to organize, aggregate, and filter the dataset once obtained from the SQL database. Since the SQL statement is executed IN the SQL database, only the functions that are in the database are available. The code you posted is a SQL statement not a Report Expression.
For example, you can't take a Report Expression and expect it to work in SSMS? No, because they are two different entities with wholly different syntax and purpose. When it comes to using built-in SSRS functions inside a SQL statement it will not work, the database has no concept of what the built in User.UserId is and as such you must use a parameter to transport the value over to the SQL query. This is definition and purpose of a parameter and why they exist.
Split is a function in SSRS which is why you see it in your expression reference, however, it is not a function in SQL. The code you posted is SQL syntax, so I am betting that this is the SQL statement that you are using to obtain your dataset. Therefore the query fails since the SQL DB does not have a Split Function.
You can add this split function to your database and the code is located here: Split String in SQL. You could also use something along the following in your where clause, the following is your updated SQL statement.
SELECT slsm_num, slsm_msid from Salesman where slsm_msid = SUBSTRING(#UserId, PATINDEX('%\%', #UserId), LEN(#UserId))
You would set the #UserId parameter's value to an expression of User!UserID rather than specifying it in your select statement.
The SSRS expression examples have a function similar to what your code is trying to accomplish if you were wanting the same thing in the report side. The function you are looking for is InStr(). On your report side you could use something along the lines of:
=Parameters!User.Value.Substring(Parameters!User.Value.IndexOf("\")+1, Parameters!User.Value.Length-Parameters!User.Value.IndexOf("\")-1)
Expression examples can be found here: MSDN Expression examples.

using date range in mdx queries

I am bit new to mdx . Thing is we want to fetch data from olap cube between two dates.The date format is yyyy-MM-dd.So please suggest me on how to use timestamp range to filter out data.
I am using this query-
SELECT
NON EMPTY {[Measures].[Keyword count]} ON COLUMNS,
NON EMPTY {Hierarchize({[keyword].[keyword].Members})} ON ROWS
FROM [Basicsearch]
WHERE CrossJoin({[Path].[/Search]}, {[Timestamp].[${styear}].[${stmonth}].[${stday}]: [Timestamp].[${eyear}].[${emonth}].[${eday}]})
but it is not giving any result and no error also.
please suggest me how to run this query
Enable SQL Logging ( look at the commented out mondrian settings in log4j.xml ) and clear the cache. Then run the MDX query and look at the SQL logs to see what SQL mondrian has generated. You'll be able to tell from that why there is no data!
Could be many things - bug in the schema, genuinely no data, or problem with the parameters.