TSQL + MDX using OPENQUERY() - column names do not exist - sql-server

I have a view against a OPENQUERY() which gets data from a SSAS cube.
MDX query looks like this:
WITH MEMBER [Measures].[Measure1] AS
(--calculation)
SELECT
{[Measures].[Measure1]}
ON 0,
NON EMPTY ([Dim1].[Dim_key].[Dim_key], [Dim2].[Dim_key].[Dim_key])
ON 1
FROM [Cube]
WHERE ([Dim3].[Hierarchy].[Level].[Member])
My problem is that when the WHERE filter results in 0 rows the view does not work, with error:
Invalid column name '[Dim1].[Dim_key].[Dim_key].[MEMBER_CAPTION]'.
Since its using the column name to have a GROUP BY
How can I force it return at least one row? Or always return the column names?
I cannot remove the NON EMPTY since whole set takes about 1 min to load.
So far I've tried these solutions:
MDX - Always return at least one row even if no data is available
Force mdx query to return column names
but it seems like it does not work since I have a where condition on another dimension.

Managed to figure it out. Added this measure which essentially replicates Dim1 members returned on the rows:
WITH MEMBER [Measures].[Measure1] AS
(--calculation)
MEMBER [Measures].[Dim_Key] AS
[Dim1].[Dim_key].CurrentMember.Member_Key
SELECT
{[Measures].[Measure1]
,[Measures].[Dim_Key]}
ON 0,
NON EMPTY ([Dim1].[Dim_key].[Dim_key], [Dim2].[Dim_key].[Dim_key])
ON 1
FROM [Cube]
WHERE ([Dim3].[Hierarchy].[Level].[Member])
So even if there are no rows I get the new measure back as one of the columns. If there are rows I get two additional columns (which have row tags) but I just don't use them in the view

Related

How to add 2 data sets in SSRS

I have 2 data sets that have the common column VNO. Now I want to get the report in ssrs like
VDate, Count('') from B for Vdate, Count('') from A for Vdate
Can anyone help me with the way, I tried the lookup but not able to get this output.
Note: I cannot join these two tables in SQL as these 2 tables are on separate instances and they are not connected and don't have permission to do so.
You need to use LOOKUPSET() . This returns an array which you can then check the length of like this
=LookupSet(Fields!InvoiceDate.Value, Fields!VDate.Value, Fields!VNO.Value, "DataSetB").Length
The 3rd argument is the returned value but as you are only getting a count, it does not matter what we return there. DataSetB is the case sensitive name of your second dataset.

How to hide columns that are not returned with dataset results using function IsMissing in SSRS

I have a stored procedure which drops either 1 or 2 columns from the result set. In my SSRS report, I have all possible columns that may come from the result set as dataset fields. I am trying to use the IsMissing function to change the column visibility, but it is not working. How can I make this functionality work?
I tried using examples from
https://sqlserverbi.blog/tag/hide-columns/
and
https://www.allaboutmssql.com/2013/01/ssrs-ismissing-visibility-function.html
where I right click the column, select Column Visibility and add an expression to the Show or hide based on an expression line.
Here is how I have been trying to use the expressions:
When I want to hide 2 of the columns I use:
=Fields!LINE_30_A.IsMissing And Fields!LINE_30_B.IsMissing
and when I want to hide only one of them I use:
=Fields!LINE_30.IsMissing
I have also tried the expressions like this:
=IIF(Fields!LINE_30_A.IsMissing And Fields!LINE_30_B.IsMissing,True,False)
I ran my stored procedure in a way that has dropped 1 of the columns from the result set. In this case the expression Fields!LINE_30.IsMissing should have been evaluated and I should be seeing the columns for Fields!LINE_30_A and Fields!LINE_30_B. But I only see the column for Fields!LINE_30 (which shouldn't be showing at all) and the other 2 columns are hidden. I also receive these 2 warnings:
1) Warning [rsErrorReadingDataSetField] The dataset ‘DataSet1’ contains a definition for the Field ‘LINE_30’. The data extension returned an error during reading the field. There is no data for the field at position 11.
2) Warning [rsMissingFieldInDataSet] The dataset ‘DataSet1’ contains a definition for the Field ‘LINE_30’. This field is missing from the returned result set from the data source.

Vlookup data greater than 0 only from two columns

On my first tab, I need to return the data from the second tab, columns A,B and C; only when the value of column A is greater than 0. I have pics to send but don't see a way to upload them. Currently using this formula, but have been unable to expand on it to get what I need.
=VLOOKUP('MSA Units'!A4, 'MSA Units'!A4:C882,1,FALSE)
I have also tried various forms of INDEX and MATCH arguments with no good results.
HERE IS REVISED LINK TO IMAGES: http://imgur.com/a/20J0v
Filter MSA Units and for columnA select all other than (Blanks). Copy ColumnsA:C of what remains visible into Daily Report Coversheet.

SQL Full Text Indexer, exact matches and escaping

I'm trying to replace a Keyword Analyser based Lucene.NET index with an SQL Server 2008 R2 based one.
I have a table that contains custom indexed fields that I need to query upon. The value of the index column (see below) is a combination of name/ value pairs of the custom index fields from a series of .NET types - the actual values are pulled from attributes at run time, because the structure is unknown.
I need to be able to search for set name and value pairs, using ANDs and ORs and return the rows where the query matches.
Id Index
====================================================================
1 [Descriptor.Type]=[5][Descriptor.Url]=[/]
2 [Descriptor.Type]=[23][Descriptor.Url]=[/test]
3 [Descriptor.Type]=[25][Descriptor.Alternative]=[hello]
4 [Descriptor.Type]=[26][Descriptor.Alternative]=[hello][Descriptor.FriendlyName]=[this is a test]
A simple query look like this:
select * from Indices where contains ([Index], '[Descriptor.Url]=[/]');
That query will results in the following error:
Msg 7630, Level 15, State 2, Line 1
Syntax error near '[' in the full-text search condition '[Descriptor.Url]=[/]'.
So with that in mind, I altered the data in the Index column to use | instead of [ and ]:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
Now, while that query is now valid, when I run it all rows containing Descriptor.Url and starting with / are returned, instead of the records (exactly one in this case) that exactly matches.
My question is, how can I escape the query to account for the [ and ] and ensure that just the exact matching row is returned?
A more complex query looks a little like this:
select * from Indices where contains ([Index], '[Descriptor.Type]=[12] AND ([Descriptor.Url]=[/] OR [Descriptor.Url]=[/test])');
Thanks,
Kieron
Your main issue is in using a SQL wordbreaker, and the CONTAINS syntax. By default, SQL wordbreakers eliminates punctuation, and normalizes numbers, dates, urls, email addresses, and the like. It also lowercases everything, and stems words.
So, for your input string:
[Descriptor.Type]=[5][Descriptor.Url]=[/]
You would have the following tokens added to the index (along with their positions)
descriptor type nn5 5 descriptor url
(Note: the nn5 is a way to simplify quering numbers and dates given in different formats, the original number is also indexed at the same position)
So, as you can see, the punctutation is not even stored in the full text index, and thus, there is no way to query it using the CONTAINS statement.
So your statement:
select * from Indices where contains ([Index], '|Descriptor.Url|=|/|');
Would actually be normalized down to "descriptor url" by the query generator before submitting it to the full text index, thus the hits on all the entries that have "descriptor" next to "url", excluding punctuation.
What you need is the LIKE statement.
Using "|" as your delimiter causes the contains query to think of OR. Which is why you are getting unexpected results. You should be able to escape the bracket like so:
SELECT * FROM Indices WHERE
contains ([Index], '[[]Descriptor.Type]=[[]12]')

ssrs: one static row matrix, multiple columns will not filter out nulls

Using a ssrs 2005 matrix client side. I want to list the multiple addresses of one person, hence one row, multiple columns. The Column field is =Fields!StreetName.Value. The data details field is =First(Fields!StreetPrefix.Value) & " " & First(Fields!StreetName.Value). The datasource has a row for each address; however, some rows will have nulls since the datasource is composed of outer joins.
The column grouping works, but the first column is always empty, (first 2 rows of datasource are null) addresses appear only after the empty column. I want to filter out nulls on the matrix, but its like the filter is ignored. I have also tried having the dataset return an empty string for a null streetname and setting the filter to =Fields!StreetName.Value != ="" but no difference.
What am I missing?
Is it not better that you filter your rows in your query? maybe this solution is better.
Have you got the filer in the right place? You can put it on the matrix and on the group.

Resources