0:00Hey it's Tim here. In today's video I'm
0:01going to be covering the three type
0:03conversion functions
0:04int, float and string. Okay let's get stuck
0:08in. Okay so what I'm going to do is I'm
0:10going to
0:10connect to a mark data set. I'm going to
0:11make this available in the description
0:13below so you
0:14can download it and have a go yourself. So
0:16I'm going to go ahead here to excel, go to
0:18my desktop
0:19and you can see I have this mark data here
0:21for type conversion. Let's open this up and
0:23I'll show
0:24you basically what's going on in this data
0:26set. It's a very very simple data set. We
0:30've got names
0:31of individuals age, year and height and
0:33inches. So what I'm going to do is I'm
0:34going to deliberately
0:36create scenarios here with this data set to
0:38sort of showcase what's possible and what's
0:41not possible
0:42with all these functions. So let's go ahead
0:45and go to sheet one and this is it. This is
0:47the basic data
0:48set we're going to work with. I'll go ahead
0:49and take an extract just to sort of start
0:51to get into
0:52a good habit and I'll keep that in the same
0:54folder here. So let's just hit save and now
0:56we're pretty
0:57much ready to go. Okay first thing I'm
0:59going to do is drag first name onto rose
1:02and then we're going
1:03to start looking at some of this
1:04information. Now if you look at this year
1:06born is at the moment
1:08in this sort of upper part which is
1:10typically where the dimensions are. So in
1:142020.2 I believe
1:16Tableau got rid of the separator that so do
1:19you where measures and dimensions were and
1:22now they
1:22have just this sort of subtle line. So
1:25essentially speaking the year we're born
1:27here is actually
1:28coming across as an integer which is why it
1:30's sort of sitting here at the top whereas
1:32everything else
1:33is coming through as a measure. So you've
1:34got age height and inches and I think this
1:36is partly
1:36because Tableau understands that this is a
1:39slightly sort of a specific data type. So
1:42it is actually
1:42able to look inside rose and give a guess
1:44as to what it might be. So let's just build
1:47this table
1:47what I'll do is I'll make everything
1:49discrete so we can just see the information
1:51. We've got some
1:52ages and names duplicating themselves here
1:55so that's good to know. What I'll also do
1:58is I'll
1:58bring out age and again I'll make this
2:00discrete just so we can see this as a tab
2:02ular formula.
2:03Then height and inches I'll do the same and
2:05again we'll do this as discrete just so we
2:08can see that.
2:08The data count we don't need that so much
2:10but that's pretty much where we are this is
2:12all our
2:13data types. So we have the scenario where
2:15we have duplicate names I wouldn't worry
2:18too much about
2:18that it's not going to cause as much of a
2:20problem especially if we keep the year in
2:22context and so
2:23we're going to be pretty much ready to go.
2:25The first function we're going to cover is
2:27changing
2:28numbers into text so let's look at the
2:30string function. In order to do this I'm
2:32just going
2:32to create a calculated field and bring in
2:34our calculation window. I'll make this a
2:36little bit
2:37smaller just so we can see more of the
2:39window here and then I'll bring this back
2:41out so you can see
2:42the functions. I'll call this string and
2:45what we need to do here is just type in the
2:48function str.
2:49So str will bring up this function and if
2:52we hit enter you'll see that it wraps
2:55itself around that
2:56and if you look on the right hand side it
2:58says returns a string given an expression.
3:00Example
3:00string age returns all the values of the
3:02age measures as string so that's exactly
3:05what we're
3:05going to do. So let's go ahead here and
3:08just type in age and if I just type in age
3:11you'll see that
3:12that comes in and at the moment age is a
3:14measure so what this is going to do is
3:15going to turn this
3:16into a piece of text. What does that mean?
3:20I'll show you so let's just say we hit
3:22apply and then
3:23we bring this into our view and notice this
3:26time around when I bring it in it's a blue
3:29item so it
3:29behaves like a dimension like a discrete
3:31item and I'm just going to put it right
3:33next to where we
3:34have the sum of age which is actually the
3:36aggregated version of the measure that we
3:38're
3:39using so if I now put that in there you'll
3:41see that because it's a string it doesn't
3:43automatically
3:44aggregate you can't really sort of do much
3:47with it there but also if this wasn't a
3:49whole number
3:50let's say this was a decimal point it would
3:52also turn this into a piece of text. Let me
3:54show you
3:55how that works so let's go in here let's
3:57change this and let's just change the
3:59height that we've
4:00got so let's say height okay height in
4:02inches let's change that into a string and
4:04then hit apply
4:05and you'll see the tableau changes that to
4:07a string now when it does that you'll
4:10notice
4:11that it doesn't just show the two decimal
4:13places that we had it actually goes into
4:15the data set
4:16and goes and gets as much precision as it
4:18can out of that number so that's just
4:20something to bear in
4:21mind if you're going to be turning floats
4:23or numbers into strings just consider the
4:26precision
4:26that you want out of that data set because
4:28if you get something like this you're
4:29probably going to
4:30have to do some cleaning up to remove the
4:32decimal point information that you need or
4:35rounding up or
4:36rounding down then returning a string just
4:38to give you something that's actually
4:39worthwhile working
4:40with because heights in inches you probably
4:43want to turn that into some other sort of
4:45metrics like
4:46maybe foot and inches like you know five
4:48foot six or something like that this is
4:50just all in inches
4:51so you maybe you could do a conversion
4:53calculation in tableau to sort of clean
4:55that up but that's
4:55pretty much a string function it works on
4:58both integers and floats and you just need
5:00to bear in
5:00mind that it will do a pretty good job of
5:02turning that including bringing back all
5:04the precision
5:05that you have inside of your numerical
5:07fields if you have something with a high
5:09level precision
5:10like floats okay let's go on to the next
5:12function okay for the next bit i'm going to
5:14show you how
5:15the integer function works and we're going
5:17to use the height in inches which is
5:19actually a float as
5:20an example to show you that so let's go
5:22ahead and create a new calculated field in
5:25this case
5:25i'm just going to call it integer okay let
5:27's just call integer and this is another
5:29very simple
5:30function just type in int and you'll see it
5:32comes up straight away hit enter and now we
5:35have our
5:35expression already now what i need to do is
5:38to put the height in inches into this so
5:40let's just
5:40go ahead and type in heights and inches hit
5:43enter and you'll see the calculation is now
5:45valid let's
5:46hit apply drag it into our view and now
5:48what i'm going to do is i'm actually going
5:50to put it right
5:51here and at the moment because an integer
5:53is coming through is like a essentially
5:55like as a measure
5:56and what i'm actually going to do is turn
5:58it into a discrete item very very shortly
6:00so i'll put it
6:01in here or create a bar chart and then now
6:03if we go back and make it a discrete item
6:05we'll actually
6:06get to see it as a table so you'll see that
6:08exactly what's happened here by turning it
6:10into
6:10an integer it basically behaves as like a
6:13whole number so there are no fractions
6:15related to this
6:16essentially the difference between a
6:18floating and integers and integers a whole
6:20number essentially
6:20like a you know 2010 could be an integer or
6:2336 could be an integer when you talk about
6:26your age
6:26generally we talk in integers no one says
6:29they are you know 33.3 years old they just
6:31say they're 33
6:32years old so in that case you're using
6:34integers however when you work with floats
6:36you get
6:37essentially a fraction related to that
6:38number so 33.3 is technically something
6:41like 33 and one third
6:42okay and so integers will basically remove
6:45that sort of precision from your number and
6:48just return
6:49the whole number this is useful if you're
6:50working with the data that maybe needs that
6:53it's actually
6:53quite common when you work with certain
6:55data sets that you might want integers over
6:57floats and so
6:58this is essentially how you do it just put
7:00that into an integer function and you get a
7:02whole
7:02number back let's click ok and now we're
7:05going to go to the next function which is
7:06essentially
7:07the float function and we're going to use
7:10this on the age as a way of figuring this
7:12out okay so
7:12let's go ahead and create a calculation
7:14here let's create calculated field i'm just
7:17going to type in
7:17float now this is a weird one because in
7:19this particular example what i'm doing is i
7:21'm applying
7:22it to age which is at the moment it's like
7:24a whole number it's just in it it's an
7:26integer but if i
7:27just go ahead and do that um let's just say
7:29float we're going to look at another way
7:31that you can
7:32see that this is a float let's just hit
7:35apply and um let's just drag this into our
7:37view and we're
7:39going to deliberately put it here in the uh
7:42top but now you can see that this is a
7:43float but it
7:44looks exactly the same as our integer and
7:47that's because there is no precision in our
7:50age data
7:51that can make this float work in sort of
7:53more detail if i head over here to the left
7:55hand side
7:56you'll see that we have age and flight they
7:58look exactly the same but if i right click
8:00on age and
8:00i go to uh change data type you'll see that
8:02this says number whole which means it's an
8:05integer
8:06whereas if i go to the float calculation we
8:07've just created which looks identical in
8:09the table
8:10and actually go to that and see change data
8:12type says number decimals this is how i
8:14know
8:14that i've actually changed the number to a
8:16float even though it looks exactly the same
8:18as an integer so this is a really important
8:21sort of semantic thing to be aware of
8:23and because it can fundamentally change the
8:25way your charts behave and also how you do
8:27things
8:28like aggregate and work with the data now
8:30that's not to say that you couldn't force
8:32decimals into
8:33the formatting let's say that i wanted this
8:35age for whatever reason to be formatted uh
8:38you know
8:38like a decimal i could still force that so
8:40if i click on format here for this age
8:42integer
8:43i just go to number custom i can still
8:45force it to have decimal places but it's
8:48still going to be a
8:50whole number okay so that's just something
8:52to be aware of what you see and what it
8:54actually is
8:55aren't necessarily linked formatting is
8:57sort of separate to what's actually
8:59happening with the
8:59data structure and that's something that
9:01catches a lot of people out especially when
9:02you want to
9:03do things like formatting currency so that
9:05's just something to be aware of okay so
9:07that's pretty
9:07much it for this video we've covered the
9:10three main type conversion functions int
9:12string and
9:13float and essentially what those functions
9:15do is they change whatever you give them
9:17whatever
9:18expression you give them into another data
9:20type now this is commonly used in use cases
9:22where you're working inside of a
9:23calculation and maybe you need to compare
9:25integers with integers
9:27or floats to floats typically when you work
9:29with data types you need to be working with
9:31the same
9:31range of data types so this is a great way
9:33of getting around that problem okay so that
9:36's very
9:36much it if you've enjoyed this video you
9:38know what to do hit a comment below let me
9:39know what
9:40you'd like to see next next week i'm going
9:42to start trying to tackle that mountain of
9:44server content that everyone's been asking
9:46for alongside still covering some functions
9:48so
9:48we will get to more complex topics i think
9:50it's just really important to cover the
9:53fundamentals
9:53so that when you talk about complex topics
9:55you can reference the fundamentals a little
9:57later on
9:58that's essentially the game plan here we're
10:00covering the simple stuff so we can do the
10:02complex stuff later on so stay tuned for
10:04that all right i'll catch you in the next
10:05video