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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
lgoggs
New Member

Changing colour for multiple series based on filter selection in clustered bar chart

Hi, I've been playing around with this and wondered if it can be done. 

 

I have a category column called 'activity', which is the y-axis on a clustered bar chart. I then have 3 series called 'current_year',  'region_ha' and 'na' that I would like to add to the x-axis. Ideally I want to be able to colour each activity different for each series for each filter selection. So, the region 'Sheffield' when selected in the filter would have a different colour for the activity 'Running' to 'Walking', and also the colours would be different for 'current_year' compared to 'region_ha' and also different for each of these for 'Liverpool'. 

 

I did think it could be done with conidtional formatting, but you only get this option when you have 1 series added for the x-axis. I think the solution may lie in creating some kind of calculated measure with various IF statements, but I'm struggling to get my head around how this would be set up and structured. 

 

I've attemped to attach an example file (Opens in a new window) with some data below if anyone is able to take a look and any help would be greatly appreciated:

 

Example Report

 

Best wishes,

 

Luke

1 ACCEPTED SOLUTION

Hi @lgoggs ,

 

For this you need to create a table with the Activity and Metric:

MFelix_0-1715182014510.png

 

Now add the folllowing measures:

Values = SWITCH(
			SELECTEDVALUE('Activity / Metric'[Metric]),
			"current_year", CALCULATE(
				SUM(activity[current_year]),
				activity[activity] = SELECTEDVALUE('Activity / Metric'[Activity])
			),
			"na", CALCULATE(
				SUM(activity[na]),
				activity[activity] = SELECTEDVALUE('Activity / Metric'[Activity])
			),
			"region_ha", CALCULATE(
				SUM(activity[region_ha]),
				activity[activity] = SELECTEDVALUE('Activity / Metric'[Activity])
			)
		)




Colors = SWITCH(

			SELECTEDVALUE(activity[region]),
			"Liverpool", SWITCH(

				SELECTEDVALUE('Activity / Metric'[Metric]),
				"current_year", "blue",
				"na", "Green",
				"region_ha", "Yellow"
			),
			"Sheffield", SWITCH(

				SELECTEDVALUE('Activity / Metric'[Metric]),
				"current_year", "pink",
				"na", "orange",
				"region_ha", "Grey"
			)
		)

Now create your visualization in the following way:

  • Y-Axis:
    • Actvity/Metric[Activity]
    • Actvity/Metric[Metric]
  • X-Axis
    • Values (Measure)
  • Condittional formatting
    • Colors (Measure)

MFelix_1-1715182706178.pngMFelix_2-1715182714414.png

 

 

You can change the colors by HEX codes if you want to.

 

PBIX file attach.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi @lgoggs ,

 

Do you want to show all the calculations (current_year, na and region_ha) alonside with activity and location or do you want only to show one of the calculations and then the vcalues of activity and location?

 

How is the setup you need? Is the same you have on the example you gave?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi Miguel, 

 

Thank you so much for having a look at this and getting in touch. Ideally I would like to show all 3 calculations (current_year, na and region_ha) alongside each activity, but only for 1 location at a time (Set and selected by the filter). 

 

I did have all 3 calculations added to the x-axis but it then removed the ability to conditionally format the colours for each region and calculation. What I was hoping for (but not sure if it's possible), would be to have it show for say 'Sheffield', then have a different colour for each activity for current_year, different colours again for each activity for na calculations and the same again for region_ha. Then all the colours would be different again when a different region is selected. 

 

Hopefully I've explained that well, but not sure I have! Please do let me know if anything is unclear at all or if you have any further questions at all. 

 

Best wishes,

 

Luke 

Hi @lgoggs ,

 

For this you need to create a table with the Activity and Metric:

MFelix_0-1715182014510.png

 

Now add the folllowing measures:

Values = SWITCH(
			SELECTEDVALUE('Activity / Metric'[Metric]),
			"current_year", CALCULATE(
				SUM(activity[current_year]),
				activity[activity] = SELECTEDVALUE('Activity / Metric'[Activity])
			),
			"na", CALCULATE(
				SUM(activity[na]),
				activity[activity] = SELECTEDVALUE('Activity / Metric'[Activity])
			),
			"region_ha", CALCULATE(
				SUM(activity[region_ha]),
				activity[activity] = SELECTEDVALUE('Activity / Metric'[Activity])
			)
		)




Colors = SWITCH(

			SELECTEDVALUE(activity[region]),
			"Liverpool", SWITCH(

				SELECTEDVALUE('Activity / Metric'[Metric]),
				"current_year", "blue",
				"na", "Green",
				"region_ha", "Yellow"
			),
			"Sheffield", SWITCH(

				SELECTEDVALUE('Activity / Metric'[Metric]),
				"current_year", "pink",
				"na", "orange",
				"region_ha", "Grey"
			)
		)

Now create your visualization in the following way:

  • Y-Axis:
    • Actvity/Metric[Activity]
    • Actvity/Metric[Metric]
  • X-Axis
    • Values (Measure)
  • Condittional formatting
    • Colors (Measure)

MFelix_1-1715182706178.pngMFelix_2-1715182714414.png

 

 

You can change the colors by HEX codes if you want to.

 

PBIX file attach.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Oh my goodness Miguel, this is incredible!!! Thank you so much for your help with this and making it's possible. I cannot tell you how many hours I've spent trying to figure that out! 😅

 

A massive thank you. I appreciate it's not straight forward, so very grateful for your time and support. 

 

 

All the best, 

 

Luke

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.