Custom Calculations in Tableau for Enhanced Data Analysis

Create a calculated field in Tableau to compute profit margin by dividing SUM(Profit) by SUM(Sales), format it as a percentage, and add it to the view as a label or tooltip as needed.

Learn how to create calculated fields in Tableau to extend your dataset with custom metrics like profit margin. This article walks through the step-by-step process of building, validating, and formatting a calculated field using multiple methods within Tableau’s interface.

Key Insights

  • Calculated fields in Tableau allow users to derive new data points—such as profit margin—by combining existing measures using functions like SUM, and can be created from the sidebar, the Analysis menu, or via field drop-downs.
  • When creating a calculated field, Tableau provides a function library with categories and examples, helping users select and apply functions like SUM correctly, even if they’re unfamiliar with Excel-style formulas.
  • Noble Desktop’s training demonstrates how to format the calculated result properly—such as converting profit margin to a percentage—and how to display it in labels or tooltips for better data visualization.

This lesson is a preview from our Tableau Course Online (includes software). Enroll in this course for detailed lessons, live instructor support, and project-based training.

Tableau calculations. So now we're gonna talk about creating calculations. If you work with pivot tables, you know you could create custom calculations.

This is pretty simple. This is just like creating calculations in a pivot table. The fields available to you in your dataset may not always be enough.

You can add fields in a custom calculation node as known as a calculated field. In order to create this field, there are many ways to create it. It's usually gonna be available in the sidebar.

So you can start from the field that you wanna use in the calculation, or you could choose to create a calculated field from the menu in the sidebar, or you can go to the analysis menu as well to create the calculated field. You're gonna give your field a name, and then you're gonna type in your calculation. We don't have a field that represents profit margin.

So we wanna create one. Perhaps we should create one using a calculated field. So what if you want the profit margin? One of the best options is to use an existing field to create that profit margin.

So I'll show you how to do this in Tableau. So let's see, would this be a good chart to use? Yeah, sure, why not? So I wanna create a calculation for profit margin. I'm gonna go to profit.

I'll click the dropdown here. I'll choose create. It's one of those create options, and I'm gonna choose create calculated field.

What does this do? It drops profit into the calculated field area because it knows I wanna use profit for my calculated field. I'm gonna click close. The other way that you can create this is you can go up here to the top.

I always know it's here because when I click this dropdown menu, it's the very first option, create calculated field. I'm gonna click that. It doesn't have profit, but I can add profit here.

How could you add profit? I can drag and drop. I can take profit here and then just drag it there. Now I have it there.

And then I'll show you where you can do it from analysis. I'll click analysis, and I'll look for the option create calculated field. Same thing, I'm starting from scratch.

Well, let's say I like to use the option where it automatically puts the field in. I'm gonna go over here, create calculated field, and I'm gonna call this profit margin. You cannot use a name that's already being used for a field, so you can't call it profit.

So I'll call it profit margin. Now the profit margin is going to be the sum of the profit divided by the sum of the sales. I need to use the sum function.

Let's say I'm really bad at Excel, and I don't know what functions are available. There's a little triangle here to the right. There's a little triangle here to the right.

I'm just gonna mention that just in case people are gonna ask me, hey, where was that thing? It's the little triangle to the right. If I click this, it shows me almost all the functions I would normally be able to access in Excel. I can search for them.

I can search them by category, number functions, string functions, date functions, type conversion. I have the whole thing here, the whole kit and caboodle. I'm looking for the sum function, so I'll type sum.

Would you give me an explanation of sum? Yeah, if I click sum, it gives me an explanation of sum. It even gives me an example, and the example that I'm looking for is actually for the field that I have right here. Now, if I like this, I can double-click.

It puts it right in there. Oh, it put it after profit. Now, if your calculation doesn't make, now, I can hide this.

How? I just click this little triangle. If this calculation doesn't make sense, it will tell me. You know, the syntax here doesn't make sense.

All right, let me take out profit. Can I drag profit in here? Yes, you can drag profit in here and put it right inside the parentheses. I wanna divide the sum of profit by the sum.

Oh, I don't have to input it. I could just type it, and it'll recognize it, just like when you type in Excel equals sum and press tab, it puts in the open and closing parentheses. Could I type profit too? Well, let's try it.

P-R-O-F. Yeah, it's a measure with a green hashtag. I'll just press tab.

That is my calculation. Is my calculation valid? It is valid. It is a valid calculation.

I'm gonna click OK. It shows up down here. Don't be disappointed it doesn't show up in your table.

It doesn't exist in your table. You just created it. So it's gonna be down here with the measures.

So I can show the profit margin? Yeah. Where would you like to show it? Well, I'd like it to be visible. Could I put it as a label? Yeah, you can take profit margin, drag it over into label.

So there it is. It's showing up as a label. It looks weird.

Yeah, it looks kinda weird. So we need to edit this. So I'm gonna go over here and what we need to do is change the format.

I'm gonna choose the format. No, wait, does that? Yeah, so I'll go to format and then I'll go over here to numbers and I wanna choose percentage. And I don't want any decimal places.

Now I'll have to check my calculation. It can't be 100%. So there's something definitely off in my calculation.

I'm gonna just have to take a look and I think I'm just off regarding something related to that. So I'm gonna go back, close this and I'll go to my profit margin. I'll click the dropdown here and choose to edit my profit margin.

Oh, it's supposed to be sales, of course. I think I just put profit twice. I think I typed it in because I was telling you, yeah, you can type profit instead of just dragging it but I actually meant to type sales.

That's what we want. Now I'll click OK and it fixed itself, yay. So again, by default, the format is not gonna show up the way that you want it to show up.

You'll have to go into format. You'll have to click in the default numbers and choose percentage because by default, it's gonna show up as a number that doesn't make sense. If I wanna put in sales, I can put sales back in.

I'll just take sales and I'll drag it over to label. And if I want the profit margin to be underneath, I'll just drag it down underneath. So that is an example of a calculated field that walks you through the steps of creating a calculated field.

You can create a calculated field for other types of calculations and then just bring it into your display. If you want, you can also bring it into your tooltip. I'll take profit margin, I'll drag it over to tooltip.

When I hover my mouse, there's my profit margin for any of the bars that I have. And it is gonna take some time and practice. There are a lot of different places you can go to and sometimes things change with updates.

Things that used to work behave a little differently based on what Tableau feels is, you know, the most common format and orientation for the information.

photo of Garfield Stinvil

Garfield Stinvil

Garfield is an experienced software trainer with over 16 years of real-world professional experience. He started as a data analyst with a Wall Street real estate investment company & continued working in the professional development department at New York Road Runners Organization before working at Noble. He enjoys bringing humor to whatever he teaches and loves conveying ideas in novel ways that help others learn more efficiently.

Since starting his professional training career in 2016, he has worked with several corporate clients including Adobe, HBO, Amazon, Yelp, Mitsubishi, WeWork, Michael Kors, Christian Dior, and Hermès. 

Outside of work, his hobbies include rescuing & archiving at-risk artistic online media using his database management skills.

More articles by Garfield Stinvil

How to Learn Tableau

Build professional data visualization and analytics skills with hands-on Tableau training. Tableau is an industry-standard platform used to analyze data and create interactive dashboards, charts, and reports that support data-driven decision making across business, government, and technical fields.

  • Explore online training options at VDCI: Learn from anywhere with flexible, fully online Tableau courses and related data analytics training options.
  • Start with an online Tableau course at VDCI: Begin with a self-paced Tableau Course Online that introduces core concepts such as data connections, visual analytics, charts, dashboards, and best practices.
  • Advance with a Tableau certificate or certification program: Build deeper analytics and visualization skills by completing the Tableau Certification Course Online, which is designed to prepare you for the professional Tableau Desktop Specialist exam.
  • Explore related courses in data and analytics: Expand your Tableau skills with complementary training in subjects that commonly work alongside Tableau in real-world workflows. This includes Excel, SQL, Python, and data analytics and AI, which are all covered in the Data Analytics Certificate.
Yelp Facebook LinkedIn YouTube Twitter Instagram