6 Replies Latest reply on Sep 3, 2016 10:41 AM by Sophia Messini

# How can I have different colors to my Measures on the map?

Hello to everybody,

I am new in the forum and I do a research in voting behavior for my master. I have create a map of my country but I want to put different colors to each politician. For example, iF the results of a local community has votted "PASOK" for a winner I want to be green, if has vote "ND" I want to be blue, if has vote "SYRIZA" I want to be pink etc.

I have all the results for every local community, if you can please help me I would be grateful.

• ###### 1. Re: How can I have different colors to my Measures on the map?

hi Sophia,

So we can do this by way of creating a calculated field, which returns '"PASOK", "ND" or "SYRIZA"...and the you can add this to the colour tile, which will colour the map.

Now the exact form of this calculation will depend on the structure/grain of your data...are you able to post a bit of the data here? (either your .twbx, or just an excel with a few hundred rows...if there is anything sensitive in the data just remove those columns, as it is the shape/grain I need to see)

• ###### 2. Re: How can I have different colors to my Measures on the map?

Hello Simon,

Here is an example of my data in excel. I want the calculation to measure if the SUM of ΠΑΣΟΚ is bigger than the others ... SUM "ΝΔ" , SUM"KKE" SUM "ΛΑΟΣ" SUM"SYRIZA" the mark must be green.

If the SUM of "ΝΔ" is bigger I want blue

If the SUM of  "KKE" is bigger I want  red

If the SUM of "ΛΑΟΣ" is bigger I want purple

If the SUM of "ΣΥΡΙΖΑ" is bigger I want Pink

and that calculate must be at every row because I have the results of every local community.

Thank you very much

• ###### 3. Re: How can I have different colors to my Measures on the map?

I would first ask or assume your data has the "Politician" assigned to each record.   If so, drag the Politician field to the Color Mark.  The set the color pallet to whatever you want.  IF this does not help, maybe you can post a sample or your packaged workbook.

• ###### 4. Re: How can I have different colors to my Measures on the map?

Hello Christopher,

thank you very much it really worked out . You can see my map here Tableau Public  ΕΚΛΟΓΙΚΟΣ ΧΑΡΤΗΣ 2009. But here is in every city and not in local communities which are about 20.000. It would have been easier for me if there was a calculate for this too.

Thank you very much for your help

• ###### 5. Re: How can I have different colors to my Measures on the map?

hi Sophia,

So, as always with Tableau there are a few ways to go about this...I've given you one with your original data structure, and one where I have pivoted the data, to have candidate going down the page

So first with the original...

So we need to find the MAX of each of the measures (which in this case is the number of votes for each candidate), as we can only check the max of 2 measures at a time we need to nest the MAX calculation

MAX(MAX(MAX(MAX([ΚΚΕ],[Λαοσ]),[ΝΔ]),[Πασοκ]),[Συριζα])

once we have this we can see which measure is equal to that value (note that if there is an equal first place, the order of the IF statement will determine what colour the city will take)

[Winner]

IF SUM([ΚΚΕ]) = MAX([Winning Votes]) THEN 'KKE'

ELSEIF SUM([Λαοσ]) = MAX([Winning Votes]) THEN 'Λαοσ'

ELSEIF SUM([ΝΔ]) = MAX([Winning Votes]) THEN 'ΝΔ'

ELSEIF SUM([Πασοκ]) = MAX([Winning Votes]) THEN 'Πασοκ'

ELSEIF SUM([Συριζα]) = MAX([Winning Votes]) THEN 'Συριζα'

END

and then you can colour on this field.

The other way I did it was to pivot the data...in general Tableau (being based on database/set theory prefers data like this...although from doing some political Vizes myself, there are times when it's good like this, and others when your original structure is best. I tend to have both, as separate data-sources and then blend between the 2)

So first to Pivot the data, I used the function Tableau provides on the connect-to-data screen

which gives me the data like this (where I have re-named the columns to candidate and votes)

From here I have used a nested FIXED LoD...the second nesting is just to it brings back a single value for each city

[Winner]

As you'll see we are doing the same check, on MAX, but as the data goes down the page we can do it in one go.

I'm not able to actually map it, as I don't have the City field tableau picks up, but have added the colour to both tables so you can see it's working. I've also, in both tables, added parts of some of the calculations so you can see how it's working.

I would also add that there are other ways too (eg. using table calcs), but these are probably the 'logically' most simple (if not the most efficient, in terms of query time...but on a data-set of this size you can get away with it!!)

Hope that does the trick, and makes sense, but please post back if not.