Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
prpranav
Contributor II
Contributor II

Coloring Qlik Sense Maps

Hey everyone!

I'm working with state voter data, and I'm trying to color each county of a state map either blue or red (Democrats or Republicans) depending on which the party won the county. I have all the data organized in one central table.

The data table lists number of votes the candidate won in each precinct (subset of county).  A preview of the table is attached below. 

In the color by expression, I tried :

if(FirstSortedValue( [Party], -aggr( sum([Candidate Votes]), [Candidate])) = 'Democratic Party'
, blue()
,if(FirstSortedValue( [Party], -aggr( sum([Candidate Votes]), [Candidate])) = 'Republican Party'
,red()))

but it returns a map of the counties with only one county colored (a picture is attached below).

I believe it is adding up all the votes in all counties and only returning one value for the winning party, but I'm not sure how to solve it. Any help would be appreciated. 

Thank you!

 

4 Replies
Lisa_P
Employee
Employee

A simpler way to do colors is to create a Master dimension for Party and customize the colors for each Party value in the Master item.  Then you can determine the party with the most votes and color by it.

prpranav
Contributor II
Contributor II
Author

Thank you so much!

I created the Master Dimension for [Party] and assigned colored for each value, but where do I put the calculation for the party with the highest votes and color each county with it?

Also, is there another way to do the calculation, because I think the firstsortedvalue is doing the entire calculation for the state at once instead of per county?

Lisa_P
Employee
Employee

Actually, my first solution is not enough. You are right, you need that expression, but, this is how it should look:

if(FirstSortedValue( [Party], -aggr( sum([Candidate Votes]), [Candidate], Party)) = 'Democratic Party'
, blue()
,if(FirstSortedValue( [Party], -aggr( sum([Candidate Votes]), [Candidate], Party)) = 'Republican Party'
,red()))

prpranav
Contributor II
Contributor II
Author

This is still resulting the same result :disappointed_face:

Is there another way to make the calculation?