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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
cottrera
Post Prodigy
Post Prodigy

DAX dynamic format bars in column chart

Hi 

 

I have a facts table that shows property equipment and the date a service is next due. This is conncted to a calendar table with the following columns - Date, Year, Month ,Month# , Is current month and is date < today

I have a bar chart that displays the property count by year / month

cottrera_0-1694607659827.png

 

Can the communit recoment a DAX function that would dymanicaly change the bar colour  based on the following criteria
If date is current month = Orange bar
If date is < today but excludes current month = Red bar
thank you Richard

1 ACCEPTED SOLUTION
some_bih
Super User
Super User

Hi @cottrera possible solution as following

In your Calendar / Date table insert column to create values later used in conditional formatting

 

Type of Month =
VAR __year=YEAR('Date'[Date])
VAR __month=MONTH('Date'[Date])
VAR __year_month_number=__year*12+__month-1

VAR __year_current=YEAR(TODAY())
VAR __month_current=MONTH(TODAY())
VAR __year_month_number_current=__year_current*12+__month_current-1

VAR __Result=
IF(
   __year_month_number = __year_month_number_current ,
   "Current month",
   --"#FFA500",--orange
   IF(
     __year_month_number <__year_month_number_current ,
     "Month before",
     -- "#ff0000", --red
     "Future month"
     -- "#000000"  --black
  )
)
RETURN __Result

 

To go to cond.formatting on bar visual put your measure (in my case it was dummy measure simple SUM (some column) and select as first picture below. 

After that, go to second picture and choose format style based on rules and in part What field should we base this on? choose just created column in Calendar / Date table "Type of Month".

Choose your colour pallete as you wish.

Did I answer correctly? Kudos appreciate / accept solution.

some_bih_0-1694638308552.png

 

some_bih_1-1694638521608.png

 

 





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

Proud to be a Super User!






View solution in original post

2 REPLIES 2
cottrera
Post Prodigy
Post Prodigy

Thank you for you quick response and solution

some_bih
Super User
Super User

Hi @cottrera possible solution as following

In your Calendar / Date table insert column to create values later used in conditional formatting

 

Type of Month =
VAR __year=YEAR('Date'[Date])
VAR __month=MONTH('Date'[Date])
VAR __year_month_number=__year*12+__month-1

VAR __year_current=YEAR(TODAY())
VAR __month_current=MONTH(TODAY())
VAR __year_month_number_current=__year_current*12+__month_current-1

VAR __Result=
IF(
   __year_month_number = __year_month_number_current ,
   "Current month",
   --"#FFA500",--orange
   IF(
     __year_month_number <__year_month_number_current ,
     "Month before",
     -- "#ff0000", --red
     "Future month"
     -- "#000000"  --black
  )
)
RETURN __Result

 

To go to cond.formatting on bar visual put your measure (in my case it was dummy measure simple SUM (some column) and select as first picture below. 

After that, go to second picture and choose format style based on rules and in part What field should we base this on? choose just created column in Calendar / Date table "Type of Month".

Choose your colour pallete as you wish.

Did I answer correctly? Kudos appreciate / accept solution.

some_bih_0-1694638308552.png

 

some_bih_1-1694638521608.png

 

 





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

Proud to be a Super User!






Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.