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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tasmiaa
Advocate I
Advocate I

How to color a filled map dynamically

I have the following data:

 

Table with countries, date, and a value

CountryValueYear
USA32016
France62016
Germany22016
USA12017
France42017
Germany52017

 

Measures:

 

Avg_Val_CurrentYear = Calculate(Average(Value), DATEADD('Date'[Date], 0, Year))   --I'm sure there was a better way

Avg_Val_PreviousYear = Calculate(Average(Value), DATEADD('Date'[Date], -1, Year))

 

My goal: 

 

Create a map where the country is red if the Avg_Val_CurrentYear is less than Avg_Val_PreviousYear and green if Avg_Val_CurrentYear is greater than Avg_Val_PreviousYear. The page will have a slicer to select the year so this would change based on the year I have selected. 

 

How can I do this? I've tried creating a calculated column in the table that marks it red or green based on the 2 measures, but it does not mark the colors properly. Any advice would be appreciated.

 

Thanks!

1 ACCEPTED SOLUTION
tasmiaa
Advocate I
Advocate I

I found the solution:

  1. Keep measure Avg_Val_CurrentYear
  2. Create a new table-
    Table = SUMMARIZE(NATURALINNERJOIN('Table', 'Date'),'Table'[Country],'Date'[Date], "Value", [Avg_Val_CurrentYear] )
  3. Create a measure on the table for previous year
    Avg_Val_PreviousYear = CALCULATE (
    AVERAGE(Value),
    ALLEXCEPT ( 'Table', 'Table'[Country], 'Table'[Date]),
    DateADD('Table'[Date], -1, Year))
  4. Create a calculated column on the table
    Color = If(Value < Avg_Val_PreviousYear, "red", "green")
  5. Create a filled map with the country, value and color
     
     
     

View solution in original post

3 REPLIES 3
tasmiaa
Advocate I
Advocate I

I found the solution:

  1. Keep measure Avg_Val_CurrentYear
  2. Create a new table-
    Table = SUMMARIZE(NATURALINNERJOIN('Table', 'Date'),'Table'[Country],'Date'[Date], "Value", [Avg_Val_CurrentYear] )
  3. Create a measure on the table for previous year
    Avg_Val_PreviousYear = CALCULATE (
    AVERAGE(Value),
    ALLEXCEPT ( 'Table', 'Table'[Country], 'Table'[Date]),
    DateADD('Table'[Date], -1, Year))
  4. Create a calculated column on the table
    Color = If(Value < Avg_Val_PreviousYear, "red", "green")
  5. Create a filled map with the country, value and color
     
     
     
v-frfei-msft
Community Support
Community Support

Hi @tasmiaa ,

 

Based on my test, it is not possible to conditional formatting in shape map in power bi.You can come up a new idea about that and add your comments there to improve Power BI and make this feature coming sooner.

 

https://ideas.powerbi.com/forums/265200-power-bi-ideas

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks, I was actually asking about a filled map and not a shape map, but I was able to figure out the issue. My solution is posted on the thread! 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.