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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PBI_newuser
Post Prodigy
Post Prodigy

Dynamic Line Color

Hi,

 

I want to show the data points in green if meet target, but the below measure shows all green.

Can anyone help on this?

 

Thanks.

 

Line Color = 
VAR currProduct =
SELECTEDVALUE ( TableB[Product] )
VAR currValue =
CALCULATE (SUMX(TableA, TableA[Rate]),ALLSELECTED(TableB),values(TableB[Product] ) )
RETURN
IF (
currProduct = "A",
IF ( currValue > 0.8, "Green", "Red" ),
IF ( currValue > 0.7, "Green", "Red" )
)

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PBI_newuser ,

 

You can follow my method below. I modified your measure.

 

Line Color = 
VAR currProduct =
SELECTEDVALUE ( TableA[Product] )
VAR currValue =
CALCULATE (SUMX(TableA, TableA[Rate]),ALLSELECTED(TableA[Product]),values(TableA[Product] ) )
RETURN
IF (
currProduct = "A",
IF ( currValue > 0.8, "Green", "Red" ),
IF ( currValue > 0.7, "Green", "Red" )
)

 

1. Here is my sample data.

TableA:

Product

Date

Rate

A

8/15/2019

0.9

A

9/15/2019

0.75

A

10/15/2019

0.45

B

11/15/2019

0.95

B

12/15/2019

0.8

B

1/15/2020

0.7

A

2/15/2020

0.6

A

3/15/2020

0.94

A

4/15/2020

0.91

B

5/15/2020

0.65

B

6/15/2020

0.44

B

7/15/2020

0.75

 

 

2. First I create a simple column chart:

1.png

 

3. Then under Data colors, set up conditional formatting on the bars:

2.png

 

4. The result is this.

3.png

 

5. Now switch the visual to a line chart.

4.png

 

 

You can check more details from here.

 

 

Best regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@PBI_newuser ,  Assuming you measure is correct. You have to use the same under conditional formatting with field options. But you have to do it on Bar and then make it line.

 

https://radacad.com/dax-and-conditional-formatting-better-together-find-the-biggest-and-smallest-num...
https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

 

steps

example of color measure

Colour = 
SWITCH(TRUE(),
Table[Date] < TODAY(), "red",
Table[Date] = TODAY(), "orange",
"green")

Color sales = if(AVERAGE(Sales[Sales Amount])<170,"green","red")
Color Year = if(FIRSTNONBLANK(Table[Year],2014) <=2016,"lightgreen",if(FIRSTNONBLANK(Table[Year],2014)>2018,"red","yellow"))

Color  = if(FIRSTNONBLANK(Table[Year],2014) <=2016 && AVERAGE(Sales[Sales Amount])<170 
,"lightgreen",if(FIRSTNONBLANK(Table[Year],2014)>2018,"red","yellow"))
Color sales = if([Sales Today] -[sales yesterday]>0,"green","red")

color =
switch ( true(),
FIRSTNONBLANK(Table[commodity],"NA") ="commodity1" && sum(Table[Value]) >500,"lightgreen",
FIRSTNONBLANK(Table[commodity],"NA") ="commodity2" && sum(Table[Value]) >1000,"lightgreen",
/// Add more conditions
"red"
)
calc

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @PBI_newuser ,

 

You can follow my method below. I modified your measure.

 

Line Color = 
VAR currProduct =
SELECTEDVALUE ( TableA[Product] )
VAR currValue =
CALCULATE (SUMX(TableA, TableA[Rate]),ALLSELECTED(TableA[Product]),values(TableA[Product] ) )
RETURN
IF (
currProduct = "A",
IF ( currValue > 0.8, "Green", "Red" ),
IF ( currValue > 0.7, "Green", "Red" )
)

 

1. Here is my sample data.

TableA:

Product

Date

Rate

A

8/15/2019

0.9

A

9/15/2019

0.75

A

10/15/2019

0.45

B

11/15/2019

0.95

B

12/15/2019

0.8

B

1/15/2020

0.7

A

2/15/2020

0.6

A

3/15/2020

0.94

A

4/15/2020

0.91

B

5/15/2020

0.65

B

6/15/2020

0.44

B

7/15/2020

0.75

 

 

2. First I create a simple column chart:

1.png

 

3. Then under Data colors, set up conditional formatting on the bars:

2.png

 

4. The result is this.

3.png

 

5. Now switch the visual to a line chart.

4.png

 

 

You can check more details from here.

 

 

Best regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

First, this doesn't color the line, which was the original request. But more importantly, WHY IN THE NAME OF ALL THAT'S HOLY should it be necessary to go through this dog and pony show just to color a series of data points? 

Greg_Deckler
Community Champion
Community Champion

@PBI_newuser - I am not aware of a way to make line colors in a Line chart visualization dynamic in terms of their color. However, the Power BI team has been adding more and more conditional or formula based formatting to things so it may be coming.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.