Thursday, 5 November 2015

Show Previous Month Data in the Report for Regions.


1) Create a Calculated field as below.

Name: Previous Month Sales
Syntax: if year([Order_Date])= year(today()) and month([Order_Date])= month(today())-1
then ([Sales]) end

2) Drag the [Region] on to Rows shelf, [Previous Month Sales] onto Columns Shelf.

Current month Data in the Report for Regions.



1) Create a Calculated field as below.

Name: Current Month Sales
Syntax:
if year([Order_Date])= year(today()) and month([Order_Date])= month(today())
then ([Sales]) end

2) Drag the [Region] on to Rows shelf, [Current Month Sales] onto Columns Shelf.

Monday, 2 November 2015

How to get the Last Day of the Given Date Data.



I am taking the Data Like below

Country Date_DB Sales Date_DB2
A     12-12                 200        12-2012
B     10-15                300        10-2015
C     02-12                20        02-2012

We are expecting like Below

Country    Sales   DB_Date_DB      LDM
A              200       12-12                31-Dec-2012
 

Procedure:

1) First Convert the Given Date Related column into exact Date like using below calculation.
(This Calculation for Date_DB, it means Date is Like 10-12)
date( "01" +  "/" +  str(left([Date DB],2))  +"/" +( "20" + str(right([Date DB],2))))



2) Use the below Calculation to Last day of the Given Date.
datepart( 'day', dateadd('day', -1, dateadd('month', 1,[Converttodate_MM-YY])))


3) Expected Output.




===============

If data is available like 12-2012 then use the below calculation to Convert into Date.
date( "01" +  "/" +  str(left([Date DB2],2))  +"/" +  str(right([Date DB2],4)))


How can we show Different Measures with different Colors



As of now, We can apply Different Measures with different Colors but there is no feasibility of applying different Colors for Different Measures  Headers.

Drag the Measure Names into Colors shelf1.png

How to Differentiate when same City name located in two Countries while showing Data on MAPS.




I have the issue Showing Hyderabad Data On Map, But  HYDERABAD city is available in INDIA,
PAKISTAN, *Eventually We used Latitude, Longitude values to Tableau
Identify exactly.*

Updating Quick Filter Values, Parameter Values

If you are creating Quick Filter on any specific field, it will show all possible values as per current data availability. (Distinct Values).
Once you update database, Quick filter won't update directly, we have to use one option on Menu Bar, select "Auto updates Quick filters".

Updating Parameter Values: 
Values of Parameter will not be changed once Database has been updated, So manually we have to open the Parameter, then Reload the values from that Specific field.

Examples of using Conditions in Calculations



If you want to know how to write Conditions in Tableau, go through the this link.



EX: List of the STATES which sales are more than 10K in 2012.

Steps:
1) Create a Calculated Field like below.
Name: States - Sales>10K in 2012
Syntax:
if attr(year( [Order Date]))= 2012 and sum([Sales])>10000 then sum([Sales] ) end





2) Drag the [State or Province],  [Order Date] on to Rows shelf, [States - Sales>10K in 2012] onto Text Marks.

3) Drag [States - Sales>10K in 2012]into filters shelf, then select "Special" option then select "Non-null values".




Fundamentals of writing Conditional Calculations in Tableau.


Conditional Calculations:

If any calculation you want to use in the report which is not there in database, then we create that calculation with right syntax at tableau level.

And we use the Calculations for customization purpose.

For An Example: Sales less than 10 K is  "Worst Sales", >10 K and < 15 K is "Average" , >15 K and < 20 K is "Above Average" , >20 K and < 50 K is "Meet Target" , >50 K and < 75 K is "Excellent Sales." 

SYNTAX:

1) If condition with 1 Possibility  without Else part
IF [Condition Matches] then [Matched Value]  end

EX: If  sum([Sales])>15000 then "Good"  end

Description: In the above example, If sales are more tan 15000 then those will be represented as "Good" (If condition matches then "Good" if Condition does not match then empty, i.e. null)
If Sales does not more then 15000 then those values are represented by empty since we did not define else part.
Next example will explains how out put will effect if we define else part.  

2) If condition with 2 Possibilities including Else part

Syntax:

IF [Condition Matches] then [Matched Value] else [Non Matched Value]  end

EX: If  sum([Sales])>15000 then "Good" else "Average" end

Description: 
In the above example, If sales are more tan 15000 then those will be represented as "Good" (If condition matches then "Good" if Condition does not match then empty, i.e. null)
If Sales does not more then 15000 then those values are represented by  "Average" since we defined else part.

3) If then else - more than 2 Possibilities

if [Condition 1 Match] then [Value1] 
elseif [Condition 2 Match] then [Value 2] 
elseif [Condition 3 Match] then [Value 3] 
elseif [Condition 4 Match] then [Value 4] 
.....................
Else [Value N] end 

EX:

If sum([Sales]) <15000 then "Below Average"
elseif  sum([Sales]) >=15000 and sum([Sales]) <25000 then "Average"
elseif  sum([Sales]) >=25000 and sum([Sales]) <50000 then "Above Average"
else "Excellent" end
=============================
Case <EXP>
when <Matches 1> then [Value 1]
when <Matches 2> then [Value 2]
when <Matches 3> then [Value 3]
Else [Value 4] end



Case [Region]
when "Central" then "Territory - 1"
when "East" then "Territory - 1"
else "Territory - 2" end

1) I want to Apply Different colors to Regions as per Sales Value.
<10 K - Color 1
>=10 K And < 15 K then Color 2
>=15 K And < 25 K then Color 3
or Color 4

2) Difference between And , Or Operators in the Calculations.
Create few reports with BUZ Requirement.

3) I want to see 2013, 2014 data in 1 color, 2011, 2015 in another color.
(Don't use Editing Color Legend option for applying colors. Use Calculations to define colors)

4) Categorize the City's into different groups by using your own business situation.

5) I want apply Different shapes as per Sales Values.
Use Question -1 as situation & define the shapes.

Note:
In SQL "IN" operator is used to filter multiple Values, As of now Tableau does not have "IN" operator in the Calculation but there is an alternative that is "OR"

EX: Select Country, Sales from Sales where country in ('India', 'Usa', 'UK') ----- SQL

Case [Region]
when "Central" then "Territory - 1"
when "East" then "Territory - 1"
else "Territory - 2" end

Or

If  [Region] = "Central" or   [Region] ="East" then "Territory - 1"
else "Territory - 2" end