Looker is a business intelligence and data analytics platform that allows users to perform table calculations. Table calculations are mathematical operations performed on columns in a data table to calculate new values or insights.
Here are some common table calculations in Looker:
- Running Total: Calculates the cumulative total of a column of values up to the current row.
- Difference: Subtracts the value of one column from another to calculate the difference between them.
- Ratio: Divides the value of one column by another to calculate the ratio between them.
- Moving Average: Calculates the average of a set of values over a specified number of preceding or following rows.
- Percentage of Total: Calculates the percentage of a column’s value in relation to the total value of all values in the same column.
- Percent Difference: Calculates the percentage difference between the value of one column and the value of another column.
To perform a table calculation in Looker, select the column(s) you want to apply the calculation to and then choose the calculation from the drop-down menu.
How to perform table calculations in Looker:
- Open a Looker dashboard and select the data table you want to perform the calculation on.
- Right-click on the column header and select “Create Calculated Field”.
- In the “Create Calculated Field” dialog box, specify the calculation you want to perform. You can use Looker’s expression language, LookML, to specify the calculation.
- Specify the name of the calculated field, and choose the data type for the result of the calculation.
- Select the “Apply to Rows” option to perform the calculation for each row in the data table. If you select “Apply to Groups”, Looker will perform the calculation for each group of rows based on the grouping you have specified.
- Click “Create” to save the calculated field. The calculated field will appear as a new column in the data table.
- You can use the calculated field in visualization or export the results to another tool for further analysis.
It’s important to note that table calculations in Looker can be computationally intensive, so it’s recommended to limit the size of the data set you are working with or to aggregate the data to a lower level of detail before performing table calculations.
or you can also do the steps as mentioned in the picture
When to Use Table Calculations & When to Use Custom Fields
Examples of table calculations in Looker
Running Total: Let’s say you have a table with a column of sales data and you want to calculate the running total of sales for each row. The calculation would look like this in LookML
calculated_field: {
type: sum
sql: ${sales}
}
Difference: Let’s say you have a table with two columns: “Quantity Sold” and “Quantity Ordered”. You want to calculate the difference between the two columns to see how much inventory is left over. The calculation would look like this in LookML
calculated_field: {
type: number
sql: ${Quantity Ordered} - ${Quantity Sold}
}
Ratio: Let’s say you have a table with two columns: “Revenue” and “Costs”. You want to calculate the ratio of revenue to costs to see how profitable your business is. The calculation would look like this in LookML
calculated_field: {
type: number
sql: ${Revenue} / ${Costs}
}
Moving Average: Let’s say you have a table with a column of daily sales data, and you want to calculate the 3-day moving average of sales. The calculation would look like this in LookML
calculated_field: {
type: average
sql: ${sales}
window_function: avg
window_function_arg: 3
}
Percentage of Total: Let’s say you have a table with a column of sales data and you want to calculate the percentage of each sale in relation to the total sales. The calculation would look like this in LookML
calculated_field: {
type: number
sql: ${sales} / total(${sales})
}
Percent Difference: Let’s say you have a table with two columns: “This Year’s Sales” and “Last Year’s Sales”. You want to calculate the percent difference between the two columns to see how sales have changed year over year. The calculation would look like this in LookML:
calculated_field: {
type: number
sql: 100 * (${This Year's Sales} - ${Last Year's Sales}) / ${Last Year's Sales}
}
About Me:-
I am Om Prakash Singh – Data Analytics Consultant , Looker Consultant , Solution Architect .
I am Highly analytical and process-oriented Data Analyst with in-depth knowledge of database types; research methodologies; and big data capture, manipulation and visualization. Furnish insights, analytics and business intelligence used to advance opportunity identification.
You’ve got data and lots of it. If you’re like most enterprises, you’re struggling to transform massive information into actionable insights for better decision-making and increased business results.
Reach out to us here if you are interested to evaluate if Looker is right for you or any other BI solution.
Pingback: What are Derived tables in Looker? - Data Analysis Experts
Pingback: How to calculate percent of total in looker? - Data Analysis Experts
Pingback: Looker Tutorial : Learn Looker from Basic to Advance Looker
Pingback: How to create a dynamic field in Looker: Use Case and Examples
Pingback: How to write LookML CASE in Looker
Pingback: Embedded Analytics in Looker: Examples and Use Cases
Pingback: How to add pagination to Looker Dashboard?
Pingback: Python Program: Swap Two Numbers in Python
Pingback: Embedded Analytics In Looker: Examples And Use Cases – SAMDI Analytics
Pingback: Looker Interview Questions And Answers - Data Analysis Experts