Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Shape Map color saturation not working

Struggling with a Shape Map for days.  I am trying to get the colors based on the Political party (Democrat, Republican, Independent). Location value is "States" which is every state in the United St...
  • PhilipTreacy's avatar
    5 years ago

    Hi Anonymous 

     

    Download example PBIX file

     

    I created some dummy data for other states then I created a column to store the color for the majority party and used that as color saturation

    Majority Color = 
    
    VAR _Dem = CALCULATE(COUNTROWS('Append1'), FILTER('Append1', 'Append1'[Party] = "Democrat" && 'Append1'[State Long] = EARLIER([State Long]) ))
    VAR _Rep = CALCULATE(COUNTROWS('Append1'), FILTER('Append1', 'Append1'[Party] = "Republican" && 'Append1'[State Long] = EARLIER([State Long]) ))
    VAR _Ind = CALCULATE(COUNTROWS('Append1'), FILTER('Append1', 'Append1'[Party] = "Independent" && 'Append1'[State Long] = EARLIER([State Long]) ))
    
    RETURN
    
    SWITCH(
    
        TRUE(),
    
        _Dem > _Rep && _Dem > _Ind, 0,
    
        _Rep > _Dem && _Rep > _Ind, 1,
    
        2
    
    )
    

     

    Because the Shape Map uses color shading, the different parties need discrete values to respresent them, each one can be assigned a specific color then.

     

    You can also do this with a Filled Map where I worked out the majority party (similar code to above)

    Majority Party = 
    
    VAR _Dem = CALCULATE(COUNTROWS('Append1'), FILTER('Append1', 'Append1'[Party] = "Democrat" && 'Append1'[State Long] = EARLIER([State Long]) ))
    VAR _Rep = CALCULATE(COUNTROWS('Append1'), FILTER('Append1', 'Append1'[Party] = "Republican" && 'Append1'[State Long] = EARLIER([State Long]) ))
    VAR _Ind = CALCULATE(COUNTROWS('Append1'), FILTER('Append1', 'Append1'[Party] = "Independent" && 'Append1'[State Long] = EARLIER([State Long]) ))
    
    RETURN
    
    SWITCH(
    
        TRUE(),
    
        _Dem > _Rep && _Dem > _Ind, "Democrat",
    
        _Rep > _Dem && _Rep > _Ind, "Republican",
    
        "Independent"
    
    )
    

    Each party being assigned the relevant color.

     

    The sample file above contains all this data and both maps.

    Regards

    Phil