Search code examples
switch-statementpowerbilinechartslicers

How do you change the data Color of a line chart in Power BI based on Slicer Selection


I have a table of selections that has no relationship and only serves to be a selector for a filter:

enter image description here

I then have this feed a slicer on my page so that when the user selectes a value, the following measure will evaluate (works great):

Metric Toggle = SWITCH(TRUE(),
SELECTEDVALUE(Metrics[Metric]) = "Current Ratio", MAX('FinancialData'[CurrentRatio])
,SELECTEDVALUE(Metrics[Metric]) = "Debt to Tangible Net Worth", MAX('FinancialData'[DebtToTNW])
,SELECTEDVALUE(Metrics[Metric]) = "Gross Sales", MAX('FinancialData'[GrossSales])
,SELECTEDVALUE(Metrics[Metric]) = "NetSales", MAX('FinancialData'[NetSales])
,SELECTEDVALUE(Metrics[Metric]) = "Current Portion of Long Term Debt", MAX('FinancialData'[CPLTD])
,SELECTEDVALUE(Metrics[Metric]) = "EBITDA", MAX('FinancialData'[EBITDA])
,0)

This measure drives a line chart. Is it possible to conditionally format the data line color on the chart for each selection? i.e If user selected "EBITDA", then line colour = Blue, If User Selected "Current Ratio", then Line Color = Red... etc


Solution

  • Deselect your Slicer value as below

    enter image description here

    Now add Metric to the Line Chart's Legend property and go to the Chart's property Data Color and you will find a list like below-

    enter image description here

    Now, select your specific colors for specific Metric value. Once you complete all the above setup, you will get your expected color for Line based on the Slicer selection.