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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

conditional colouring by selection

Hi community, 

I have the following requirements: 

- Period (numeric, not as date) as filter selection

- periods greater than selected period should be blue coloured

- periods less than selected period should be grey coloured

 

Well, I have a measure called #SelectedPeriod (e.g. 202003) and period-column #MyPeriodField

 

Now, I'm trying to tell PBI something like this: 

IF #MyPeriodField is less than #SelectedPeriod than "#01B8AA" else "#333333"

 

The problem is I can't create a measure because I'm unable to use column-values or rather non-aggregated values in measures

AND 

calculated colums are fixed and can't be used in conditional formatting. 

 

So, do you have an idea how I could get PBI to format my table by selected period? 

 

 
 
201801201802201803201804201805201806201807
544564554645686456
4212454214541216

 

1 ACCEPTED SOLUTION
lkalawski
Resident Rockstar
Resident Rockstar

Hi inf1948,

To achieve what you described you must follow these steps:

  1. Create a separate table that will have the period dictionary and use it in the slider.
  2. Create a measure that will dynamically check whether the selected period is larger or smaller.

 

Measure = 
VAR _period = SELECTEDVALUE('Period'[Period])
VAR _tableperiod = SELECTEDVALUE('Table'[Period])
RETURN IF(_period > _tableperiod,0,1)

_period - dictionary, tableperiod - table with data

 

  • Use this measure in Conditional formatting.Ex3.png

The result (I used background color, but you can also use this for font color):

Ex1.pngEx2.png



_______________
If I helped, please accept the solution and give kudos! 😀

View solution in original post

3 REPLIES 3
lkalawski
Resident Rockstar
Resident Rockstar

Hi inf1948,

To achieve what you described you must follow these steps:

  1. Create a separate table that will have the period dictionary and use it in the slider.
  2. Create a measure that will dynamically check whether the selected period is larger or smaller.

 

Measure = 
VAR _period = SELECTEDVALUE('Period'[Period])
VAR _tableperiod = SELECTEDVALUE('Table'[Period])
RETURN IF(_period > _tableperiod,0,1)

_period - dictionary, tableperiod - table with data

 

  • Use this measure in Conditional formatting.Ex3.png

The result (I used background color, but you can also use this for font color):

Ex1.pngEx2.png



_______________
If I helped, please accept the solution and give kudos! 😀

Anonymous
Not applicable

awesome, thank you!

amitchandak
Super User
Super User

Create a measure and then use that in the conditional format of a font under advance control choose the field and use this measure

Color Date = if(FIRSTNONBLANK('Date'[datekey],blank()) <="201803","black","blue")

Color Date = if(FIRSTNONBLANK('Date'[date],TODAY()) <today(),"lightgreen","red")

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

 

Check steps

https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

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

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.