Thursday, June 25, 2015

Temp Tables in Tableau Error

Temp Tables in Tableau


Assume a Stored Procedure in SQL server using some Temp Tables and return a result set from that Temp Table like below:

CREATE PROC Tableau_Temp
AS
BEGIN

SELECT * INTO #Temp_Sales FROM Sales.SalesOrderDetail

SELECT * FROM #Temp_Sales


END

Once you add Stored Procedure in Tableau then you will get below error.




The reason for this error is, Tableau always return the first result set from Stored Procedure. In the case above it would be “123456 rows affected” see in message tab. So avoid these such type of messages in SP and apply “SET NOCOUNT ON” as below:

ALTER PROC Tableau_Temp
AS
BEGIN

SET NOCOUNT ON

SELECT * INTO #Temp_Sales FROM Sales.SalesOrderDetail

SELECT * FROM #Temp_Sales


END


Once you have done this change then you will get desire output as below:

So use SET NOCOUNT ON


Friday, May 15, 2015

SSRS: Change Font and Background Color at Run time


SSRS: Change Font and Background Color at Runtime.

Sometimes Clients requirements are very unexceptional but we need to fulfill them. So the requirement is that Client could change the Font properties as per their will like they can change “Font Family, Font Size, Font Style and Background Color of Tablix Header” at any time.

So if N numbers of reports are deployed then “How do you do it”? Solution is given below:

Create a table in Database like Font_Table or whatever the name you want to give. Add columns like: Font_Family, Font_Size, Back_Color etc. Insert only one row in table, if you need more values then add columns but insert only single row as below:

CREATE TABLE FONT_TABLE
(
Font_Family  VARCHAR(50),
Font_Size   VARCHAR(10),
Back_Color   VARCHAR(10)
)

INSERT INTO FONT_TABLE VALUES
('Calibri', 10pt, 'GREEN')


SELECT * FROM FONT_TABLE




NOW, we can use this table values in our SSRS report’s properties. We can write expression of Font Properties and many others as well.
Add new dataset in report. Add query “Select * from Font_Table”


Go to table header -> Properties -> BackgroundColor -> Expressions -> Choose color field as below:


For Font Family:
   




Do it same for Font Size, Font Weight etc.
See the output:




NOW if I change the values in my Font_Table in database and just refresh the report, you will see the difference:

UPDATE FONT_TABLE
SET Font_Family = 'Verdana',
      Font_Size = '12pt',
      Back_Color = 'Orange'







So you can change any property at runtime which having expression functionality and also we can use RGB Code for Color property instead of writing color name. If you use this property at the time of developing reports then all reports will be effected. Enjoy and let me know for any question. Thanks.

SSRS: Break Table Data in Vertical Format

SSRS: Break the Table Data in Vertical Format.

We generally get the requirement to break the table records, so that some specific counts of records appear in each page. For ex- if your table has 100 records and you want to break this table in 20 records each page then we use “Ceiling Function” and add page break BUT if I want to break this table Vertically like below:


This is only a single table which is breaking vertically, so below are some steps to achieve this funcanality.

  1. Create a ROW Group on Tablix and write expression “Ceiling(ROWNUMBER(NOTHING) / 5)
  2. Create COLUMN Group on Tablix and write expression “(ROWNUMBER(NOTHING)  ) mod 5
  3. Add Fields and Lable as below:


  1. You can change Ceiling and MOD value as per choice but if both remain same then it would be good.

Preview the Report and you will get desired output: Thanks.





Monday, March 9, 2015

Tableau Interview Question


Difference between tableau extensions .twb and .twbx

Twbx:
1. .twbx file is a Tableau Packaged Workbook, meaning it is the original .twb file grouped together with the datasource(s) in one package. 
2. .twbx files can be considered analogous to specialized zip files, in which these “zip” files contain all the information necessary to work in Tableau.   
3.  The primary advantage to using .twbx files is that analysis can be performed without network/internet connections to your data because your data is already present on your computer in this packaged file.
Twb:
1. The .twb file alone is not enough to perform any analysis because it only contains Tableau’s instructions for interacting with a datasource.  
2. In actuality, .twb files are XML files specially tailored to interact with datasources.
3. They are custom built to make the awesome visualizations that Tableau generates.  Here you can see a picture of a .twb file opened in Notepad++.

What are the major differences between tableau version 7.0 and tableau version 8.0?

  • New visualizations are introduced like treemap, bubble chart and box and whisker plot
  • We can copy worksheet directly from one workbook to another workbook
  • Introduced R script
What is page self?
         Page shelf breaks a view into series of pages so you can better analyze how a specific          field affects the rest of the data in the view.
         eg: If a dimension (country) is placed on the page shelf- each country will have one              page




What is the Dimensions and Measures?

DimensionA dimension is a field that can be considered an independent variable.

Dimensions typically produce headers when added to the rows or columns shelves in the view. By default, Tableau treats any field containing qualitative, categorical information as a dimension. This includes, for instance, any field with text or dates values.


This means that a measure can be aggregated for each value of the dimension. For instance, you might calculate the Sum of “Sales” for every “State”. In this case the State field is acting as a dimension because you want to aggregate sales for each state. The values of Sales are dependent on the State, so State is an independent field and Sales is a dependent field.


Measure:A measure is a field that is a dependent variable; that is, its value is a function of one or more dimensions.


Measures typically produce axes when added to the rows or columns shelves. By default, Tableau treats any field containing numeric (quantitative) information as a measure.


This means that a measure is a function of other dimensions placed on the worksheet. For instance, you might calculate the Sum of “Sales” for every “State”. In this case, the Sales field is acting as a measure because you want to aggregate the field for each state. But measures could also result in a non-numeric result. For instance, you might create a calculated measure called “Sales Rating” that results in the word “Good” if sales are good and “Bad” otherwise. In this case the “Sales Rating” field acts as a measure even though it produces a non-numeric result. It is considered a measure because it is a function of the dimensions in the view.

What is the criteria to blend the data from multiple data sources.?

There should be a common dimension to blend the data source into single worksheet.

For example, when blending Acutal and Target sales data, the two data sources may have a Date field in common. The Date field must be used on the sheet. Then when you switch to the secondary data source in the Data window, Tableau automatically links fields that have the same name. If they don’t have the same name, you can define a custom relationship that creates the correct mapping between fields.


Can we use Groups and Sets in calculation field.?

  • Groups: No, we can not use Groups in calculation fields.
  • Sets: Yes, we can use Sets in calculation fields.

Difference between Grouping and Sets.?

·       Groups – Combine dimension members into higher level categories.
·       Sets – Create a custom field based on existing dimensions that can be used to encode                     the view with multiple dimension members across varying dimension levels.

Can we have multiple value selection in parameter?
No


What is Dual Axis.?
You can compare multiple measures using dual axes, which are two independent axes that are layered on top of each other. Dual axes are useful when you have two measures that have different scales.

For example, the view below shows Dow Jones and NASDAQ close values over time.

To add the measure as dual axis drag the field to the right side of the view and drop it when you see a black dashed line. You can also select Dual Axis on the field menu for the measure.


The two axes are independent scales but the marks are layered in the same pane.



Can we use Parameter in Filter.?
Yes, We can use.




How many types of filters are there in Tableau.?


In Tableau, there are three types of filters.  More explicitly, there are three different ways to limit the data that is displayed by your graph. Each of these has its own strengths and weaknesses, and we will look at them one at a time.

These types are
1.            Custom SQL "Filters"
2.            Context Filters
3.            Traditional Filters.  

Custom SQL Filters:
Custom SQL "Filter" is a WHERE clause that is placed in the SQL that queries the data to be used in the workbook.  "Filter" is a Tableau term that technically applies only to Context and Traditional Filters; however, the Custom SQL "Filter" emulates the behavior of a global Context Filter, so we will refer to it as such.  By construction, Custom SQL "Filters" are always global.  The most common reason for using a Custom SQL "Filter" is to limit the size of a data extract.  The smaller your data extract, the more quickly your charts will load.  In other words, you can make more complex charts without sacrificing efficiency.

One of the ways to create a Custom SQL "Filter" is during the Server Connection process.

Context Filters:
a Context Filter is a filter in Tableau that affects the data that is transferred to each individual worksheet.  Context Filters are great when you want to limit the data seen by the worksheet.  When a worksheet queries the data source, it creates a temporary, flat table that is uses to compute the chart.  This temporary table includes all values that are not filtered out by either the Custom SQL or the Context Filter.  Just like with Custom SQL "Filters", your goal is to make this temporary table as small as possible.

Context Filters have a few advantages over Traditional Filters.  First, they execute more quickly than Traditional Filters.  They are also executed before Traditional Filters and can be executed all at once, which further improves efficiency.  However, they do have one drawback.  It takes time for the filter to be placed into context.  A rule of thumb, from Tableau's KnowledgeBase, is to only place a filter into context if it reduces the data by at least 10%.

A Context Filter is created by dragging a field onto the "Filters" Shelf and editing the filter.  Then, you can Right-Click the field on the shelf and select "Add to Context."  If you have multiple context filters, you can CTRL-Select them all and add them to context in a batch.  This will improve the efficiency of your filter.

Traditional Filters:
Traditional Filter is exactly what most people think of when they think of filters.  When Tableau is creating the visualization, it will check to see if a value is filtered out by a Traditional Filter.  Since this is not performed at the table level, it is the slowest of all filter types.  However, it does have the advantage of being performed after the Context Filters.  This is a necessity if you are dealing with complex "Top N" filters.  A Traditional Filter can be created by simply dragging a field onto the "Filters" Shelf.

 

 

What is data blending..? When do you use this.?


Data blending is when you blend data from multiple data sources on a single worksheet. The data is joined on common dimensions. Data Blending does not create row level joins and is not a way to add new dimensions or rows to your data.

We use this when we want to fetch data from different sources and make use in single worksheet.


When do you use horizontal and vertical components?


We can use these when we want to have all sheets or filter to move in single shot.. however we can still  create the dashboard without this also.. this allows us to make our work simple

Name the components of dashboard?

·                     Horizontal
·                     Vertical
·                     Text
·                     Images etc

How Does Tableau Work?


While Tableau lets you analyze databases and spreadsheets like never before, you don’t need to know anything about databases to use Tableau. In fact, Tableau is designed to allow business people with no technical training to analyze their data efficiently.
Tableau is based on three simple concepts:
1.            Connect - Connect Tableau to any database that you want to analyze. Note that Tableau does not import the data. Instead it queries to the database directly.
2.            Analyze - Analyzing data means viewing it, filtering it, sorting it, performing calculations on it, reorganizing it, summarizing it, and so on.
Using Tableau you can do all of these things by simply arranging fields of your data source on a Tableau worksheet. When you drop a field on a worksheet, Tableau queries the data using standard drivers and query languages (like SQL and MDX) and presents a visual analysis of the data.
3.            Share - You can share results with others either by sharing workbooks with other Tableau users, by pasting results into applications such as Microsoft Office, printing to PDF or by using Tableau Server to publish or embed your views across your organization.

 What is Tableau Desktop?
  • Tableau Desktop is a data visualization application that lets you analyze virtually any type of structured data and produce highly interactive, beautiful graphs, dashboards, and reports in just minutes. After a quick installation, you can connect to virtually any data source from spreadsheets to data warehouses and display information in multiple graphic perspectives. Designed to be easy to use, you’ll be working faster than ever before.


Tuesday, January 6, 2015

CONTAINS - New Feature in SQL 2012

This is new Feature added in SQL Server 2012

CONTAINS can search for:
·         A word or phrase.
·         The prefix of a word or phrase.
·         A word near another word.
·         A word inflectionally generated from another (for example, the word drive is the inflectional stem of drives, drove, driving, and driven).
·         A word that is a synonym of another word using a thesaurus (for example, the word "metal" can have synonyms such as "aluminum" and "steel").

Examples:

A. Using CONTAINS with <simple_term>
The following example finds all products with a price of $80.99 that contain the word "Mountain".
USE AdventureWorks2012;
GO
SELECT Name, ListPrice
FROM Production.Product
WHERE ListPrice = 80.99
   AND CONTAINS(Name, 'Mountain');
GO
B. Using CONTAINS and phrase with <simple_term>
The following example returns all products that contain either the phrase "Mountain" or "Road".
USE AdventureWorks2012;
GO
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, ' Mountain OR Road ')
GO
C. Using CONTAINS with <prefix_term>
The following example returns all product names with at least one word starting with the prefix chain in the Name column.
USE AdventureWorks2012;
GO
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, ' "Chain*" ');
GO
D. Using CONTAINS and OR with <prefix_term>
The following example returns all category descriptions containing strings with prefixes of either "chain" or "full".
USE AdventureWorks2012;
GO
SELECT Name
FROM Production.Product
WHERE CONTAINS(Name, '"chain*" OR "full*"');
GO
E. Using CONTAINS with <proximity_term>
The following example searches the Production.ProductReview table for all comments that contain the word "bike" within 10 terms of the word "control" and in the specified order (that is, where "bike" precedes "control").
USE AdventureWorks2012;
GO
SELECT Comments
FROM Production.ProductReview
WHERE CONTAINS(Comments , 'NEAR((bike,control), 10, TRUE)');
GO
F. Using CONTAINS with <generation_term>
The following example searches for all products with words of the form ride: "riding," "ridden," and so on.
USE AdventureWorks2012;
GO
SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, ' FORMSOF (INFLECTIONAL, ride) ');
GO
G. Using CONTAINS with <weighted_term>
The following example searches for all product names containing the words performancecomfortable, or smooth, and different weights are given to each word.
USE AdventureWorks2012;
GO
SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, 'ISABOUT (performance weight (.8),
comfortable weight (.4), smooth weight (.2) )' );
GO
H. Using CONTAINS with variables
The following example uses a variable instead of a specific search term.
USE AdventureWorks2012;
GO
DECLARE @SearchWord nvarchar(30)
SET @SearchWord = N'Performance'
SELECT Description
FROM Production.ProductDescription
WHERE CONTAINS(Description, @SearchWord);
GO
I. Using CONTAINS with a logical operator (AND)
The following example uses the ProductDescription table of the AdventureWorks2012 database. The query uses the CONTAINS predicate to search for descriptions in which the description ID is not equal to 5 and the description contains both the word Aluminum and the word spindle. The search condition uses the AND Boolean operator.
USE AdventureWorks2012;
GO
SELECT Description
FROM Production.ProductDescription
WHERE ProductDescriptionID <> 5 AND
   CONTAINS(Description, 'Aluminum AND spindle');
GO
J. Using CONTAINS to verify a row insertion
The following example uses CONTAINS within a SELECT subquery. Using the AdventureWorks2012 database, the query obtains the comment value of all the comments in the ProductReview table for a particular cycle. The search condition uses the AND Boolean operator.

USE AdventureWorks2012;
GO
INSERT INTO Production.ProductReview
(ProductID, ReviewerName, EmailAddress, Rating, Comments)
VALUES
(780, 'John Smith', 'john@fourthcoffee.com', 5,
'The Mountain-200 Silver from AdventureWorks2008 Cycles meets and exceeds expectations. I enjoyed the smooth ride down the roads of Redmond');

-- Given the full-text catalog for these tables is Adv_ft_ctlg,
-- with change_tracking on so that the full-text indexes are updated automatically.
WAITFOR DELAY '00:00:30';  
-- Wait 30 seconds to make sure that the full-text index gets updated.

SELECT r.Comments, p.Name
FROM Production.ProductReview r
JOIN Production.Product p
ON
 r.ProductID = p.ProductID

AND r.ProductID = (SELECT ProductID
                  FROM Production.ProductReview
                  WHERE CONTAINS (Comments,
                                 ' AdventureWorks2008 AND
                                   Redmond AND
                                   "Mountain-200 Silver" '));

GO
K. Querying on a document property
The following query searches on an indexed property, Title, in the Document column of the Production.Document table. The query returns only documents whose Title property contains the string Maintenanceor Repair.

Use AdventureWorks2012;
GO
SELECT Document FROM Production.Document
  WHERE CONTAINS(PROPERTY(Document,'Title'), 'Maintenance OR Repair');
GO