0% found this document useful (0 votes)
17 views

Data Visulaization R Programming Manual

r progrmming

Uploaded by

mnaganikhith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Data Visulaization R Programming Manual

r progrmming

Uploaded by

mnaganikhith
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

St.

MARTIN’S ENGINEERING COLLEGE


UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

LAB MANUAL

DATA VISUALIZATION - R PROGRAMMING/ POWER BI

ACADEMIC YEAR : 2023-2024

YEAR / SEM : II-II

COURSE NAME : DATA VISUALIZATION - R PROGRAMMING/ POWER BI

COURSE CODE : CS310PC


St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

INDEX
S.NO NAME OF PROGRAM
1 Vision and Mission of Institution and Department
2 COs, POs, PSOs & PEOs
3 Syllabus
4 List of Experiments
5 Programs
6 Content Beyond Syllabus
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

INSTITUTE VISION & MISSION, DEPARTMENT VISION & MISSION


Institute Vision and Mission

To become an institute of excellence by creating high quality and

Vision of the innovating engineering and management professionals who would take
Institute the world into their stride through sustainable growth in technology and
management.

To instill moral values and promote technological, intellectual and


ethical environment to the students with an in-depth and exceptional
education that makes them employment ready as per the emerging trends
Mission of the
in industry and to invoke the desire of innovation as a process of
Institute
life-long learning for a successful career in engineering and
management.

Department Vision and Mission

To arise as a centre of excellence in the field of Computer Science and


Design and committed to indoctrinate discipline and offering best
Vision of the
Technical Education and Research Opportunities to the students who
Department
can contribute to the advancement and welfare of the society with ethical
and moral values.

M1. To implement the latest industry trends in teaching learning process


in order to make students globally competent
Mission of the
M2. To work together with industries and research organizations to
Department gauge the market trends and train accordingly

M3. To make an encouraging environment which fosters ethics and


human values to make students responsible citizens.
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

COs, POs, PSOs &


PEOs

COURSE OBJECTIVES
S. NO. Course Objectives

Effective use of Business Intelligence (BI) technology (Tableau) to


apply data visualization
1
2 To discern patterns and relationships in the data.
2 To build Dashboard applications.
3

4 To communicate the results clearly and concisely.


5 To be able to work with different formats of data

COURSE OUTCOMES
CO. NO. Course Outcomes BTL
Understand How to import data into Tableau.
CO1 BTL-1
Understand Tableau concepts of Dimensions and Measures.
CO2 BTL-2
Develop Programs and understand how to map Visual Layouts and
C03 Graphical Properties. BTL-3
Create a Dashboard that links multiple visualizations.
C04 BTL-4
Use graphical user interfaces to create Frames for providing
C05 solutions to real world problems BTL-5
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

PROGRAM OUTCOMES
S. NO. Program Outcomes Level Expertise
Assessed by
Engineering knowledge: Apply the knowledge of
PO1 mathematics, science, engineering fundamentals, and an 3 Assignments
engineering specialization to the solution of complex
engineering problems.
Problem analysis: Identify, formulate, review research
PO2 literature, and analyze complex engineering problems 3 Assignments
reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for
complex engineering problems and design system
PO3 components or processes that meet the specified needs 3 Mini Projects
with appropriate consideration for the public health and
safety, and the cultural, societal, and environmental
considerations.
Conduct investigations of complex problems: Use
research-based knowledge and research methods
PO4 including design of experiments, analysis and 3 Projects
interpretation of data, and synthesis of the information to
provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate
techniques, resources, and modern engineering and IT
PO5 tools including prediction and modeling to complex 2 Mini Projects
engineering activities with an understanding of the
limitations.
The engineer and society: Apply reasoning informed by
the contextual knowledge to assess societal, health, safety,
PO6 legal and cultural issues and the consequent 1 --
responsibilities relevant to the professional engineering
practice.
Environment and sustainability: Understand the impact
PO7 of the professional engineering solutions in societal and 1 --
environmental contexts, and demonstrate the knowledge
of, and need for sustainable development.
Ethics: Apply ethical principles and commit to
PO8 professional ethics and responsibilities and norms of the 2 --
engineering practice.
Individual and team work: Function effectively as an
PO9 individual, and as a member or leader in diverse teams, 1 --
and in multidisciplinary settings
Communication: Communicate effectively on complex
engineering activities with the engineering community
PO10 and with society at large, such as, being able to 1 --
comprehend and write effective reports and design
documentation, make effective presentations, and give and
receive clear instructions.
Life-long learning: Recognize the need for, and have the
PO11 preparation and ability to engage in independent and life- 1 --
long learning in the broadest context of technological
change.
Project management and finance: Demonstrate
knowledge and understanding of the engineering and
PO12 management principles and apply these to one’s own 2 Projects
work, as a member and leader in a team, to manage
projects and in multidisciplinary environments
1- None 2- Supportive 3- Highly Related
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

PROGRAM SPECIFIC OUTCOMES

PSO Proficiency
Program Specific Outcomes Level
No. Assessed by

To apply the skills of the capacity to employ


knowledge of mathematics and computing to
PSO1 suggest workable ideas and solutions to specific 3 Lectures,
issues creativity and design with the ability to build Assignments
reliable and supportable software by considering
societal, environmental and ethical considerations.
The capacity to create user interactive system with
engineering expertise, design expertise and
knowledge of programming languages and tools to
PSO2 3 Projects
develop skills in the thrust areas of multimedia,
product/web design, cyber security, digital
analytics and other interactive systems to develop
multi-disciplinary projects.
To apply and focus on user experience, interaction
design methods in all IT Products and services to
PSO3 2 Guest Lectures
understand, analyze and develop computer
programs for efficient design of computer-based
system of various complexity
1-None 2-Supportive 3-Highly Related
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in

DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)

PROGRAM EDUCATIONAL OBJECTIVES


Expertise &
S.No. Program Educational Objectives Level
Assessed By

Be able to apply the vital principles of computer Lecture,


PEO1 3
science, mathematics skills and design skills to solve Assignments
real world problems
Be able to apply their knowledge and skills acquired Lecture,
PEO2 3
to solve the issues in real world design problems and Assignments
to develop feasible systems
Able to function effectively in their profession and
PEO3 1 ----
exhibit good competency with social awareness and
responsibility
Lecture,
Ability to apply the gained knowledge to improve the 2
PEO4
society ensuring ethical and moral values. Assignments
St. MARTIN’S ENGINEERING COLLEGE
UGC Autonomous
NBA & NAAC A+ Accredited
Dhulapally, Secunderabad – 500100
www.smec.ac.in
DEPARTMENT OF COMPUTER SCIENCE AND DESIGN (CSG)
DATA VISUALIZATION - R PROGRAMMING/ POWER BI
II B. TECH- I SEMESTER (R22)
Course Code Programme Hours/Week Credits Maximum Marks
L T P C CIE SEE Total
CS310PC B. Tech
0 0 2 1 40 60 100
COURSE OBJECTIVES
To learn
1. Effective use of Business Intelligence (BI) technology (Tableau) to apply data
visualization
2. To discern patterns and relationships in the data.
3. To build Dashboard applications.
4. To communicate the results clearly and concisely.
5. To be able to work with different formats of data sets.
COURSE OUTCOMES
At the end of the course a student should be able to
1. Understand How to import data into Tableau.
2. Understand Tableau concepts of Dimensions and Measures.
3. Develop Programs and understand how to map Visual Layouts and Graphical
Properties.
4. Create a Dashboard that links multiple visualizations.
5. Use graphical user interfaces to create Frames for providing solutions to real world
problems.
Lab Problems:

1. Understanding Data, What is data, where to find data, Foundations for building Data
Visualizations, Creating Your First visualization?
2. Getting started with Tableau Software using Data file formats, connecting your Data
to Tableau, creating basic charts(line, bar charts, Tree maps),Using the Show me
panel.
3. Tableau Calculations, Overview of SUM, AVR, and Aggregate features, Creating
custom calculations and fields.
4. Applying new data calculations to your visualizations, Formatting Visualizations,
Formatting Tools and Menus, Formatting specific parts of the view.
5. Editing and Formatting Axes, Manipulating Data in Tableau data, Pivoting Tableau
data.
6. Structuring your data, Sorting and filtering Tableau data, Pivoting Tableau data.
7. Advanced Visualization Tools: Using Filters, Using the Detail panel, using the Size
panels, customizing filters, Using and Customizing tooltips, Formatting your data
with colors.
8. Creating Dashboards & Storytelling, creating your first dashboard and Story,
Design for different displays, adding interactivity to your Dashboard, Distributing
& Publishing your Visualization.
9. Tableau file types, publishing to Tableau Online, Sharing your visualizations,
printing, and Exporting.
10. Creating custom charts, cyclical data and circular area charts, Dual Axis charts.

TEXT BOOKS
1. Thomas Rahlf. Data Visualisation with R. Springer International Publishing, New York,
2017. ISBN 978-3-319-49750-1.
2. Lawrence Leemis. Learning Base R. Lightning Source, 2016. ISBN 978-0-9829174-80
3.
REFERENCE BOOKS

1. Microsoft Power BI cookbook, Brett Powell, 2nd edition.


2. R Programming for Data Science by Roger D. Peng (References)
3. The Art of R Programming by Norman Matloff Cengage Learning India.
WEB REFERENCES
1. R Programming for Beginners Paperback – 21 Jul 2017.

E -TEXT BOOKS

1. R For Beginners by Emmanuel Paradise.


2. R Inferno by Patrick Burns.

MOOCS COURSES

1. https://www.coursera.org › learn › r-programming


2. https://www.classcentral.com/course/open2study-chemistry-building-blocks-of-the-
world-1297
List of Experiments

. 1 Understanding Data, What is data, where to find data, Foundations for building
Data Visualizations, Creating Your First visualization?

WHERE TO FIND DATA


1. Google Dataset Search ·
2. Kaggle · 3. Data.Gov ·
4. Datahub.io ·
5. UCI Machine Learning Repository ·
5. Earth Data ·
6. CERN Open Data Portal ·

What is data visualization?


Data visualization is the graphical representation of information and data. By using visual
elements like charts, graphs, and maps, data visualization tools provide an accessible way to
see and understand trends, outliers, and patterns in data. Additionally, it provides an excellent
way for employees or business owners to present data to non-technical audiences without
confusion Foundations for building visualizations

When you first connect to a data source, such as the Superstore file, Tableau will display the
data connection and the fields in the data pane on the left sidebar. Fields can be dragged
from the data pane onto the canvas area or onto various shelves, such
as Rows, Columns, Color, or Size. We'll see that, placement of the fields will result in
different encodings of the data, based on the type of field.
The Sales field is used as a measure in this view. Specifically, it is being aggregated as a sum.
When you use a field as a measure in the view, the type aggregation (such
as SUM, MIN, MAX, AVG) will be shown on the active field. In the preceding example, the
active field on Rows clearly indicates the sum aggregation of Sales: SUM(Sales).

The Region field is a dimension with one of four values for each record of
data: Central, East, South, or West. When the field is used as a dimension in the view, it
slices the measure. So instead of an overall sum of sales, the preceding view shows the sum
of sales for each region.

Oracle Analytics to create a dataset. The dataset provides the data for creating visualizations.
1. Sign in to Oracle Analytics.
2. On the Home page, click Create, and then click Dataset.
3. In Create Dataset, click Drop data file here or click to browse. In File Upload,
click sample_revenue.xlsx, and then click Open.

4. In Create Dataset Table from sample_revenue.xlsx, click OK. Click Save . In


Save Dataset As, enter Sample Revenue in Name, and then click OK.
5. In the Join Diagram, click Create Workbook.
2. Getting started with Tableau Software using Data file formats, connecting your Data to
Tableau, creating basic charts (line, bar charts, Tree maps),Using the Show me panel.

Importing Data in Tableau

Once you’ve installed Tableau Public, we can open it and load the data. In this tutorial, we are
going to use the dataset of water withdrawals per capita from Our World in Data. For
context, water withdrawal refers to the quantity of freshwater taken from surface water, such
as rivers, lakes, and groundwater, and used for agriculture, industry, and domestic purposes.
As you probably know from the current news cycle, there is a large variability in the available
quantity of freshwater across the world. We’ll be using Tableau to visualize these disparities
between countries.

You’ll need to first download the CSV file, and then save it as a text file, as Tableau Public
can only load certain file types. You can view which file types you can load on the Start Page.
Click ‘Text File’ in the left menu and open your text file. The new page shows the data preview
and the corresponding fields of the dataset. We can see that we have four fields and 640 rows.
Each row corresponds to a different country and to a different year.

Many of Tableau's operations are similar to those used in Excel, such as renaming, changing
the data type, or adding new fields. First, we'll modify the names of the first two fields into
‘Country Name’ and ‘Country Code’. Here, we don’t need to change the data type, since
Tableau automatically recognizes the type of field. We'll also need to have the latitude and the
longitude to build an interactive geographical map later. This is possible by changing
the geographic role of the 'Country Name' field from 'None' to 'Country/Region'. Next, we
press the Sheet 1 button, and latitude and longitude appear as additional fields.

Joining Datasets in Tableau


Start by downloading the dataset containing all countries and their corresponding continents
from Our World in Data. Then, download the CSV file containing the population of each
country here.

Once they are available in your file system, we can join the datasets. We drag the table
containing the continents to the canvas. To build a relationship between the two tables, we
need to specify the field names we wish to join from the datasets. The target field in the water
withdrawals dataset is 'Country Name', while 'Entity' is the target field from the second table.
The equal operator (=) is selected to combine tables. Follow the same procedure to combine
the world population table with our target data.

Et voilà! Now the three tables are linked based on the target fields and matching field names.
This step will be useful for the next data visualizations.

Adding Filters and Colors to the View

Now that we are satisfied with our data, we can open the first worksheet which will contain
our first analysis. Let’s create a chart that shows the evolution of water withdrawals over time.
On the left, we have our loaded tables that have a relationship with each other. For now, let’s
focus only on the water withdrawals data. We distinguish the categorical fields marked in blue
(such as 'Country Name') from the numerical fields (for example 'Year') that are colored in
green. We also have the previously generated latitude and longitude fields.

To create the chart, we use the following steps:

• Drag the 'Year' field to the Columns shelf to create a column for each year.
• Drag the number of the water withdrawals to the Rows shelf.
• Add the country name to the View by inserting it into the Marks shelf. Since the aim is to
distinguish the number of water withdrawals for each country, we select the mark type of the
'Country Name' and click the color option.
• The chart is difficult to read when it includes so many countries. Let’s narrow it down and
focus only on three countries: the United States, China, and Egypt. Drag the 'Country Name'
field onto the Filters shelf. Select only the values we are interested in and press 'Ok'.

Notice that there is high variability in terms of the quantity of freshwater across the world, in
particular between the chosen countries. Later we can examine the relationship between water
withdrawals and the populations of countries.

Map Views in Tableau

Here comes the fun part: In the previous section, we saw that a scatterplot isn’t an efficient
way to display the water withdrawals of all the countries as there are so many. To create a
chart that can accommodate all the countries, we can use the World Map, our location
population data, and the latitude and longitude coordinates. These three fields are all necessary
to create a map view. Check here for troubleshooting map views in Tableau.

Creating a map view requires the following steps:

1. The fastest way to create the initial world map is to click the 'Country Name' field, which will
then be added automatically to the Marks field. However, there are two other alternatives: you
can drag it to the Marks field or drop it below the area where the chart is being built. All these
methods will create a map where every country present in the dataset is denoted with a dot.

2. Add information on the quantity of freshwater across the world. But there is an issue in the
dataset: some countries don’t have the water withdrawal information for each year, so we
want to show the latest value for each country instead of filtering the year.

For this purpose, we create a calculated field, which consists of building a new field based
on other fields. In this case, we want to select the most recent or highest value of the Year
field within the three groups. This new field will be called “max year per country”. Use the
following formula to calculate the field. For each country, continent, and year, specified by
the expression FIXED, we find the most recent year, which corresponds to the maximum of
the year MAX([Year]). {FIXED [Country Name],[Continent],[Year]: MAX([Year])}

3. Insert the new calculated field into the Filters shelf. This step is important because the max
year per country field becomes the context filter for this data visualization.

4. Drag the max year per country field to the Marks field. Then, do the same for the 'Total
Water Withdrawal Per Capita' field. Next, we can select the mark type of 'Total Water
Withdrawal Per Capita' and click the color option.

We can now observe how much water the countries are using and derive important insights.
For example, there is a massive difference between the amount of water withdrawal in the
United States (extremely high) and countries in Africa. All of these details are captured by
this vivid representation.

Building a Dashboard in Tableau

As you have seen, each data visualization needs to be created on a different worksheet. In this
example, we save the previous world map in a worksheet with the name water, as to not
confuse it later. Next, we created a barplot that shows the water withdrawals per continent,
filtering with max year per country like before. This worksheet has been named continent.

After building two or more charts, it’s possible to combine them into a dashboard:

• Create the dashboard by clicking on the New Dashboard icon at the bottom of the window. It
will open a new dashboard with the sheets created previously on the left-hand side.
• Start to combine them by dragging the Water worksheet onto the canvas.
• Do the same with the Continent worksheet, which will be placed at the bottom of the map.
Story Building

An effective alternative to the dashboard can be a Story. A story is composed of multiple


views or dashboards and constitutes one of the key features of Tableau. As the name suggests,
the main idea is to tell the story of your data by combining different data visualizations. There
is also the possibility to add text descriptions to the charts.

So, let’s begin to create the story:

• Click the ‘New Story’ icon at the bottom


• Drag the existing sheets onto the story. It is similar to creating slides for a presentation, with
a view for each slide and a navigator bar to go from one chart to another.
• The navigator bar assigns a default name for each view. If you prefer to specify the content of
each chart, it’s better to change the names of the captions in the navigator bar.
• Add a text observation to the World Map.
3. Tableau Calculations, Overview of SUM, AVR, and Aggregate features, Creating
custom calculations and fields.

Data Aggregation in Tableau

In Tableau, you can aggregate measures or dimensions, though it is more common to


aggregate measures. Whenever you add a measure to your view, an aggregation is applied to
that measure by default. The type of aggregation applied varies depending on the context of
the view.

Change the Aggregation of a Measure in the View

When you add a measure to the view, Tableau automatically aggregates its values. Sum,
average, and median are common aggregations; for a complete list,

The current aggregation appears as part of the measure's name in the view. For
example, Sales becomes SUM(Sales). Every measure has a default aggregation which is set
by Tableau when you connect to a data source. You can view or change the default
aggregation for a measure.

You can aggregate measures using Tableau only for relational data sources.
Multidimensional data sources contain data that is already aggregated. In Tableau,
multidimensional data sources are supported only in Windows.

You can change the aggregation for a measure in the view from its context menu:

Aggregating Dimensions
You can aggregate a dimension in the view as Minimum, Maximum, Count, or Count
(Distinct). When you aggregate a dimension, you create a new temporary measure column,

so the dimension actually takes on the characteristics of a measure.

Note: The Count (Distinct) aggregation is not supported for Microsoft Access data sources,
and for Microsoft Excel and Text File data sources using the legacy connection. If you are
connected to one of these types of data sources, the Count (Distinct) aggregation is
unavailable and shows the remark "Requires extract." If you save the data source as an extract,
you will be able to use the Count (Distinct) aggregation.

Another way to view a dimension is to treat it as an Attribute. Do this by


choosing Attribute from the context menu for the dimension. The Attribute aggregation has
several uses:

• It can ensure a consistent level of detail when blending multiple data sources.

• It can provide a way to aggregate dimensions when computing table calculations,


which require an aggregate expression.

• It can improve query performance because it is computed locally.


Tableau computes Attribute using the following formula:

IF MIN([dimension]) = MAX([dimension]) THEN MIN([dimension]) ELSE "*" END

The formula is computed in Tableau after the data is retrieved from the initial query. The
asterisk (*) is actually a visual indicator of a special type of Null value that occurs when there
are multiple values. See Troubleshoot Data Blending(Link opens in a new window) to learn
more about the asterisk.

Below is an example of using Attribute in a table calculation. The table shows sales by market,
market size, and state. Suppose you wanted to compute the percent of total sales each state
contributed to the market. When you add a Percent of Total quick table calc (see Quick Table
Calculations(Link opens in a new window)) that computes along State, the calculation
computes within the red area shown below. This is because the Market Size dimension is
partitioning the data.

List of Predefined Aggregations in Tableau

Sometimes it is useful to look at numerical data in an aggregated form such as a summation


or an average. The mathematical functions that produce aggregated data are called aggregation
functions. Aggregation functions perform a calculation on a set of values and return a single
value. For example, a measure that contains the values 1, 2, 3, 3, 4 aggregated as a sum returns
a single value: 13. Or if you have 3,000 sales transactions from 50 products in your data
source, you might want to view the sum of sales for each product, so that you can decide which
products have the highest revenue.

You can use Tableau to set an aggregation only for measures in relational data sources.
Multidimensional data sources contain aggregated data only.

Note: Using floating-point values in combination with aggregations can sometimes lead to
unexpected results. For details, see Understanding data types in calculations(Link opens in a
new window).

Tableau provides a set of predefined aggregations that are shown in the table below. You can
set the default aggregation for any measure that is not a calculated field that itself contains an
aggregation, such as AVG([Discount]). See Set the Default Aggregation for a Measure. You
can also set the aggregation for a field already in the view. For details, see Change the
Aggregation of a Measure in the View.

Set the Default Aggregation for a Measure

You can set the default aggregation for any measure that is not a calculated field that itself
contains an aggregation, such as AVG([Discount]). A default aggregation is a preferred
calculation for summarizing a continuous or discrete field. The default aggregation is
automatically used when you drag a measure to a view.

To change the default aggregation:

Right-click (control-click on Mac) a measure in the Data pane and select Default
Properties > Aggregation, and then select one of the aggregation options.
How to Disaggregate Data
Whenever you add a measure to your view, an aggregation is applied to that measure by
default. This default is controlled by the Aggregate Measures setting in the Analysis menu.

If you decide you want to see all of the marks in the view at the most detailed level of
granularity, you can disaggregate the view. Disaggregating your data means that Tableau
will display a separate mark for every data value in every row of your data source.

To disaggregate all measures in the view:

• Clear the Analysis >Aggregate Measures option. If it is already selected,

click Aggregate Measures once to deselect it.

When Aggregate Measures is selected, Tableau will attempt to aggregate measures in the
view by default. This means that it collects individual row values from your data source into
a single value (which becomes a single mark) adjusted to the level of detail in your view.

The different aggregations available for a measure determine how the individual values are
collected: they can be added (SUM), averaged (AVG), or set to the maximum (MAX) or
minimum (MIN) value from the individual row values.

For a complete list of the available aggregations, List of Predefined Aggregations in


Tableau.

The level of detail is determined by the dimensions in your view—for information about the
concept of level of detail, see How dimensions affect the level of detail in the view.

Disaggregating your data can be useful for analyzing measures that you may want to use
both independently and dependently in the view. For example, you may be analyzing the
results from a product satisfaction survey with the Age of participants along one axis. You
can aggregate the Age field to determine the average age of participants or disaggregate the
data to determine at what age participants were most satisfied with the product.

Disaggregating data can be useful when you are viewing data as a scatter plot. See Example:
Scatter Plots, Aggregation, and Granularity.

Start building the scatter plot

There are various ways to add detail to a basic scatter plot: you can use dimensions to add
detail, you can add additional measures and/or dimensions to the Rows and Columns
shelves to create multiple one-mark scatter plots in the view, or you can disaggregate the
data. And, you can also use any combination of these options. This topic looks at these
alternatives using the Sample-Superstore data source.

To create the initial view, follow these steps:

1. Place the Sales measure on the Columns shelf.

2. Place the Profit measure on the Rows shelf.


The measures are automatically aggregated as sums. The default aggregation (SUM) is
indicated in the field names. The values shown in the tooltip show the sum of sales and
profit values across every row in the data source.

Try adding more fields to the rows and columns shelves

Revert to the original one-mark view and follow these steps to develop the scatter plot view
by adding fields to the Rows and Columns shelves.

1. Drag the State dimension to the Columns shelf.

Even if you drop Continent to the right of SUM(Sales), Tableau moves it to the left
of SUM(Sales). This is because you cannot insert a dimension within a continuous
axis. Instead, your view shows a separate axis for each member of the dimension.

2. Drag the Segment dimension to the Rows shelf.

You now have a view that provides an overview of Sales and Profit across states and
customer segments. It can be interesting to hover over the marks in the view to see
tooltip data for various segments:
4. Applying new data calculations to your visualizations, Formatting Visualizations,
Formatting Tools and Menus, Formatting specific parts of the view.

calculated fields for many, many reasons. Some examples might include:

• To segment data

• To convert the data type of a field, such as converting a string to a date.

• To aggregate data

• To filter results

• To calculate ratios

Types of calculations

You create calculated fields using calculations. There are three main types of calculations
you can use to create calculated fields in Tableau:

• Basic calculations - Basic calculations allow you to transform values or members at


the data source level of detail (a row-level calculation) or at the visualization level of
detail (an aggregate calculation).

• Level of Detail (LOD) expressions - Just like basic calculations, LOD calculations
allow you to compute values at the data source level and the visualization level.
However, LOD calculations give you even more control on the level of granularity
you want to compute. They can be performed at a more granular level (INCLUDE), a
less granular level (EXCLUDE), or an entirely independent level (FIXED) with
respect to the granularity of the visualization.

For more information, see Create Level of Detail Expressions in Tableau(Link opens
in a new window).

• Table calculations - Table calculations allow you to transform values at the level of
detail of the visualization only. For more information, see Transform Values with
Table Calculations(Link opens in a new window).

The type of calculation you choose depends on the needs of your analysis and the question
you want to answer.

Create a calculated field

Once you have determined the type of calculation you want to use, it's time to create a
calculated field. This example uses a basic calculation.

Note: The example in this article uses the Sample-Superstore data source that comes with
Tableau Desktop. To follow along with the steps in this article, connect to the Sample-
Superstore saved data source and navigate to Sheet 1.

1. In Tableau, select Analysis > Create Calculated Field.


2. In the Calculation Editor that opens, do the following:

o Enter a name for the calculated field. In this example, the field is
called, Discount Ratio.

o Enter a formula. This example uses the following formula:

IIF([Sales] !=0, [Discount]/[Sales],0)

This formula checks if sales is not equal to zero. If true, it returns the discount
ratio (Discount/Sales); if false, it returns zero.

Tip: To see a list of available functions, click the triangle icon on the right-side of the
Calculation Editor.

Each function includes syntax, a description, and an example for your reference.

Double-click a function in the list to add it to the formula.

For more tips, see Tips for Working with Calculated Fields in Tableau.

3. When finished, click OK.

The new calculated field is added to Measures in the Data pane because it returns a
number. An equal sign (=) appears next to the data type icon. All calculated fields
have equal signs (=) next to them in the Data pane.

Use a calculated field in the view

Step 1: Build the view

1. From Dimensions, drag Region to the Columns shelf.

2. From Dimensions, drag Category to the Rows shelf.

3. On the Rows shelf, click the plus icon (+) on the Category field to drill-down to
Subcategory.

The view updates to look like this:

Step 2: Add the calculated field to the view

1. From Measures, drag Discount Ratio to Color on the Marks card.

The view updates to highlight table.


You can see that Binders are heavily discounted in the Central region. Notice that
Discount Ratio is automatically aggregated as a sum.

2. On the Rows shelf, right-click SUM(Discount Ratio) and select Measure


(Sum) > Average.

The view updates with the average of discount ratio shown.

Edit a Calculated Field

If at any time you need to change a calculation, you can edit the calculated field and it will
update across your entire workbook.

To edit a calculated field:

1. In the Data pane, right-click the calculated field and select Edit.

2. In the Calculation Editor that opens, you can do the following:

o Edit the name of the calculated field.

o Update the formula.

For this example, the formula is changed to return a discount ratio for orders
over 2000 USD in sales:

IIF([Sales] > 2000, [Discount]/[Sales],0)

3. Click OK.

The view updates to reflect the changes automatically. You do not need to re-add the
updated calculated field to the view.

EXP5

Pivot Data from Columns to Rows


Applies to: Cloud, Desktop, Server

Sometimes, analyzing data that is stored in a crosstab format can be difficult in Tableau. When
working with Microsoft Excel, text file, Google Sheets, and .pdf data sources, you can pivot
your data from crosstab format into columnar format. If you are working with other data
sources, you can Pivot using custom SQL (Tableau Desktop).

For example, suppose you have the number of devices sold by quarter for three vendors in
three separate fields. You can pivot your data so that the vendor is in one field and the number
of devices sold is in another field.
Pivot the data

After you have set up the data source, in the grid, select two or more columns. Click the drop-
down arrow next to the column name, and then select Pivot. New columns called "Pivot field
names" and "Pivot field values" are created and added to the data source. The new columns
replace the original columns that you selected to create the pivot.

Add to the pivot

To add more data to the pivot, select another column, click the drop-down arrow next to the
column name, and then select Add Data to Pivot. Make sure that the pivot columns and
values look as expected before you begin your analysis.

To remove a pivot, click the drop-down arrow next to the name of a pivot column, and then
select Remove Pivot.
Troubleshooting pivots

• Red fields in the view and fields with exclamation points in the Data pane: Because
the original fields are replaced with new pivot fields, any references to the original
fields in the view will no longer work. They cause fields to become red in the view or
show a red exclamation point next to the field in the Data pane.

• Null values in the grid: If all of the original fields used in the pivot are removed, for
example in an extract refresh, null values display in the pivot fields.

• No pivot option: Pivot appears when you select two or more columns in a single
Microsoft Excel, text file, Google Sheets, and .pdf data source. If using a different data
source in Tableau Desktop, you can use custom SQL to pivot.

Pivot using custom SQL (Tableau Desktop)

You can also use custom SQL to pivot your data, even if you aren't working Excel, text file,
Google Sheets, and .pdf data sources. When you use the UNION ALL operator in a custom
SQL query, you can take values from distinct columns and put them into a new column.

For example, suppose you have a table called Contest.

Contest
Runner Start Time End Time

Amanda 9/3/2016 3:04 PM 9/3/2016 3:25 PM

Oscar 9/3/2016 3:04 PM 9/3/2016 3:21 PM

William 9/3/2016 3:04 PM 9/3/2016 3:16 PM

To optimize your analysis of this data in Tableau, you can use the following custom SQL
query to pivot the "Start Time" and "End Time" columns so that their values are in a single
column.

Select [Runner]
, 'Start' as [Action]
, [Start Time] as [Time]
From [Contest]
Union ALL
Select [Runner]
, 'End' as [Action]
, [End Time] as [Time]
From [Contest]

The above custom SQL query does the following:

• Pivots the Start Time column header into a string value called Start and adds that
value to a new column called Action.

• Pivots the End Time column header into a string value called End and adds that
value to a new column called Action.

• Pivots the Start Time and End Time columns so that their values are in a new
column called Time.

The following table shows the results of this custom SQL query.

To pivot data using custom SQL

1. Connect to your data.

2. Double-click the New Custom SQL option in the left pane. For more information,
see Connect to a Custom SQL Query.

3. In the Edit Custom SQL dialog box, copy and paste the following custom SQL query
and replace the contents with information about your table:

Select [Static Column]


, 'New Value (from Column Header 1)' as [New Column Header]
, [Pivot Column Values 1] as [New Values]
From [Table]
Union ALL
Select [Static Column]
, 'New Value (from Column Header 2' as [New Column Header]
, [Pivot Column Values 2] as [New Values]
From [Table]
Union ALL
Select [Static Column]
, 'New Value (from Column Header 3' as [New Column Header]
, [Pivot Column Values 3] as [New Values]
From [Table]

Where the following is true:

o Static Column: A comma-delimited list of the columns from Table, both


dimensions and measures, which should not be included in the pivot.

o New Value (from Column Header 1-3): New names that you give to the
original column headers, which are used as row values in the pivot.

o Pivot Column Values 1-3: The columns whose values need to be pivoted into
a single column.

o New Column Header: The name you give the new column that contains the
new row values from New Value (from Column Header 1-3).

o New Values: The name give the new column that contains the original values
from Pivot Column Values 1-3.

o Table: The table that you connected to.

4. Click OK.
5. Editing and Formatting Axes, Manipulating Data in Tableau data, Pivoting Tableau
data.

Pivot Data from Columns to Rows

you have the number of devices sold by quarter for three vendors in three separate fields.
You can pivot your data so that the vendor is in one field and the number of devices sold is

in another field.

Pivot the data

After you have set up the data source, in the grid, select two or more columns. Click the
drop-down arrow next to the column name, and then select Pivot. New columns called
"Pivot field names" and "Pivot field values" are created and added to the data source. The
new columns replace the original

Add to the pivot

To add more data to the pivot, select another column, click the drop-down arrow next to the
column name, and then select Add Data to Pivot. Make sure that the pivot columns and
values look as expected before you begin your analysis.

To remove a pivot, click the drop-down arrow next to the name of a pivot column, and then
select Remove Pivot.

Troubleshooting pivots

• Red fields in the view and fields with exclamation points in the Data pane:
Because the original fields are replaced with new pivot fields, any references to the
original fields in the view will no longer work. They cause fields to become red in
the view or show a red exclamation point next to the field in the Data pane.

• Null values in the grid: If all of the original fields used in the pivot are removed, for
example in an extract refresh, null values display in the pivot fields.

• No pivot option: Pivot appears when you select two or more columns in a single
Microsoft Excel, text file, Google Sheets, and .pdf data source. If using a different
data source in Tableau Desktop, you can use custom SQL to pivot.

Pivot using custom SQL (Tableau Desktop)

You can also use custom SQL to pivot your data, even if you aren't working Excel, text file,
Google Sheets, and .pdf data sources. When you use the UNION ALL operator in a custom
SQL query, you can take values from distinct columns and put them into a new column.

For example, suppose you have a table called Contest.

Contest
Runner Start Time End Time
Amanda 9/3/2016 3:04 PM 9/3/2016 3:25 PM
Oscar 9/3/2016 3:04 PM 9/3/2016 3:21 PM
William 9/3/2016 3:04 PM 9/3/2016 3:16 PM

To optimize your analysis of this data in Tableau, you can use the following custom SQL
query to pivot the "Start Time" and "End Time" columns so that their values are in a single
column.

Select [Runner]
, 'Start' as [Action]
, [Start Time] as [Time]
From [Contest]
Union ALL
Select [Runner]
, 'End' as [Action]
, [End Time] as [Time]
From [Contest]
6. Structuring your data, Sorting and filtering Tableau data, Pivoting Tableau data.

Organize and Customize Fields in the Data Pane

The Data pane has many features and functions to help you organize and customize your
data fields, find fields, and hide fields.

Organize the Data Pane

You can reorganize the items in the Data pane from its default layout using folders or
through sorting.

Group fields in folders

To make data sources with many fields easier to work with, you can organize the Data pane
items into folders. Items like fields, parameters, and sets can be grouped into folders.

Click the Group by Folder option in the Data pane menu, or in a field's context menu.

Notes on grouping options

• When you connect to a single table in your data source, grouping by folder is enabled
by default.

• When you connect to a data source with multiple tables, grouping by table is
enabled.

• When the Group by Data Source Table option is selected, the dimensions and
measures are grouped according to the database table they belong to. This is
especially useful when you have several joined tables.

• "Group by" options are only available for relational data sources—not for
multidimensional (cube) data sources.

Group fields into folders

1. In the Data pane, select the fields you want to group together or right-click (control-
click on Mac) an empty area in the Data pane.

2. Click Folders > Create Folder.

3. When prompted, name the new folder.

After you create a folder structure, you can drag fields from one folder to another or
duplicate a field you want to have available in more than one folder.

Add a field to a folder

• Drag a field on top of the folder name to add the field to the folder. If the folder is
expanded, you can drag the field into the general area of the folder.
Sort fields in the Data pane

When organizing the Data pane with or without folders, you can have Tableau sort the items.
These Sort by options are also located in the Data pane menu.
7. Advanced Visualization Tools: Using Filters, Using the Detail panel, using the Size
panels, customizing filters, Using and Customizing tooltips, Formatting your data with
colors.

To create a visualization, drag the data fields you want to visualize to the workspace,
then Lens uses visualization best practices to apply the fields and create a visualization that
best displays the data.

With Lens, you can:

• Create area, line, and bar charts with layers to display multiple indices and chart
types.
• Change the aggregation function to change the data in the visualization.
• Create custom tables.
• Perform math on aggregations using Formula.
• Use time shifts to compare the data in two time intervals, such as month over month.
• Add annotations and reference lines.

Create visualizationsedit
If you’re unsure about the visualization type you want to use, or how you want to display the
data, drag the fields you want to visualize onto the workspace, then let Lens choose for you.

If you already know the visualization type you want to use, and how you want to display the
data, use the following process.

Choose the visualization type.

1. Before you drag fields to the workspace, open the Visualization type dropdown,
then select the visualization you want to use.
2. To view more visualizations that Lens automatically created for the fields,
click Suggestions. If one of the Suggestions meets your visualization needs,
click Save and return to add it to the dashboard.

Choose the data you want to visualize.

1. Drag the fields directly to the layer pane. Lens automatically selects the aggregation
function.
2. If you want to learn more about the data a field contains, click the field.
3. To visualize more than one data view, click Add layer, select the layer type, then
select the data view.

Edit and delete.

1. To change the aggregation Quick function and display options, click the field in the
layer pane.
2. To delete a field, close the configuration options, then click X next to the field.

3. To duplicate a layer, click in the layer pane, then select Duplicate layer.

4. To clear the layer configuration, click in the layer pane, then select Clear
layer.
You can manually apply the changes you make, which is helpful when creating large and
complex visualizations. To manually apply your changes, click Settings in the toolbar, then
deselect Auto-apply visualization changes.

Change the fields listedit


Change the fields list to display a different data view, different time range, or add your own
fields.

• To create a visualization with fields in a different data view, open the data view
dropdown, then select the data view.

For more information about data views, refer to Create a data view.

• If the fields list is empty, change the time filter.


• To add fields, open the data view dropdown, then select Add a field to this data
view.

For more information about adding fields to data views and examples, refer
to Explore your data with runtime fields.

Create custom tablesedit


Tables are highly customizable, and provide you with text alignment, value formatting,
coloring options, and more.

1. From the Visualization type dropdown, select Table.


2. Drag the fields you want to visualize to the workspace.
3. To sort or hide the columns, click the arrow next to the column heading, then select
an option.

All columns that belong to the same layer pane group are sorted in the table.

4. To change the display options, click a Metrics field in the layer pane, then configure
the following options:

• Name — Specifies the field display name.


• Collapse by — Aggregates all metric values with the same value into a single
number.
• Value format — Specifies how the field value displays in the table.
• Text alignment — Aligns the values in the cell to the Left, Center,
or Right.
• Hide column — Hides the column for the field.
• Directly filter on click — Turns column values into clickable links that
allow you to filter or drill down into the data.
• Summary row — Adds a row that displays the summary value. When
specified, allows you to enter a Summary label.
• Color by value — Applies color to the cell or text values. To change the
color, click Edit.
8. Creating Dashboards & Storytelling, creating your first dashboard and Story,
Design for different displays, adding interactivity to your Dashboard, Distributing
& Publishing
your Visualization.

let table showing sales per year per country.

Create another table, which will sit underneath this in the dashboard, showing the total discount.
Notice the filter for Market, which applies to both worksheets.

Build your dashboard using a vertical container, making the table resize

Our dashboard is going to be very simple, containing the 2 tables and a filter.

Create a new dashboard and drag in the Country table. Next drag in a Vertical
Container below the table.
The next step is to place the Country table into the container.

This is important – to drop an object into a Tableau container, click-drag and hold it over the
container. When the container outline turns blue you can drop the object; when the container
outline is blue it means the item will fit within it.
9. Tableau file types, publishing to Tableau Online, Sharing your visualizations,
printing, and Exporting.

Tableau File Types and Folders

You can save your work using several different Tableau specific file types: workbooks,
bookmarks, packaged data files, data extracts, and data connection files. Each of these file
types are described below. For related details, see Save Your Work.

• Workbooks (.twb) – Tableau workbook files have the .twb file extension. Workbooks
hold one or more worksheets, plus zero or more dashboards and stories.

• Bookmarks (.tbm) – Tableau bookmark files have the .tbm file extension. Bookmarks
contain a single worksheet and are an easy way to quickly share your work. For more
information, see Save a bookmark(Link opens in a new window).

• Packaged Workbooks (.twbx) – Tableau packaged workbooks have the .twbx file
extension. A packaged workbook is a single zip file that contains a workbook along
with any supporting local file data and background images. This format is the best way
to package your work for sharing with others who don’t have access to the original
data. For more information, see Packaged Workbooks.

• Extract (.hyper) – Tableau extract files have the .hyper extension. Extract files are a
local copy of a subset or entire data set that you can use to share data with others, when
you need to work offline, and improve performance. For more information, see Extract
Your Data.

• Data Source (.tds) – Tableau data source files have the .tds file extension. Data source
files are shortcuts for quickly connecting to the original data that you use often. Data
source files do not contain the actual data but rather the information necessary to
connect to the actual data as well as any modifications you've made on top of the actual
data such as changing default properties, creating calculated fields, adding groups, and
so on. For more information, see Save Data Sources.

• Packaged Data Source (.tdsx) – Tableau packaged data source files have the .tdsx
file extension. A packaged data source is a zip file that contains the data source file
(.tds) described above as well as any local file data such as extract files (.hyper), text
files, Excel files, Access files, and local cube files. Use this format to create a single
file that you can then share with others who may not have access to the original data
stored locally on your computer. For more information, see Save Data Sources.

These files can be saved in the associated folders in the My Tableau Repository directory,
which is automatically created in your My Documents folder when you install Tableau. Your
work files can also be saved in other locations, such as your desktop or a network directory.

Changing the Repository Location

You can specify a new location for the Tableau repository if you are not using the default
location in your Documents folder. For instance, if you are required to have your data on a
network server instead of on your local machine, you can point Tableau at the remote
repository.
1. Select File > Repository Location.

2. Select a new folder that will act as the new repository location in the Select a
Repository dialog box.

3. Restart Tableau so that it uses the new repository.

Changing the repository location does not move the files contained in the original repository.
Instead, Tableau creates a new repository where you can store your files.
10. Creating custom charts, cyclical data and circular area charts, Dual Axis charts.

Create Dual Axis Charts

A dual axis chart is used to present the relationship between two variables. More specifically,
these charts are useful for demonstrating the relationship between two or more measures with
different amplitude and scale. The dual axis charts help in presenting plenty of information in
the limited space present on your dashboard and also allows you to understand the trends, you
may have missed otherwise.

For example, in our US Super Store dataset, we have the Profit and Sales measures. These two
measures have different magnitude and scale. Let’s directly dive into the implementation in a
stepwise manner.

Here, for our visualization, we are going to use three attributes Sub-Category from the
dimensions and two measures i.e. Profit and Sales.

Open a new worksheet and add the Sub-category from the dimension pane to the Columns

Now pick Sales from the Measures pane and drop in the Row shelf below the Sub-Category.
Similarly, Select Profit measure and drop next to the Sales in Row shelf. After this step, your
visualization will look as shown in the image below.

Here we have two charts present on multiple axes. The next step is to convert these two
different charts into a dual axis chart. For this click on the triangle present on the profit pill in
the rows shelf.

Hereafter, you will have a drop-down menu just select the Dual axis option from that.

Once you select the Dual axis boom! your visualization changes completely.

Creating dual-axis charts in Tableau

Although you have a dual axis visualization, they are on different scales. Now there is a
need to bring both measures on the same scale using synchronize axis. For this right-click on
any axis Profit or Sales and select synchronize axis from the menu. As shown in the following
image

You might also like