Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I have Table Sales with this fields: Value and Date and I have a Table Calendar with Date, Year, Month, Week, Day and Month_Name.
I need to create a bar chart showing sales by week, making the last week's bar a different color than the rest.
It must be dynamic and if change the year and/or the month, the last week in the chart must be a different color.
Please can somebody help me?
Solved! Go to Solution.
Hi, @SantiagoRandado
Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.
Steps:
Measures:
Color =
VAR _lastDay =
CALCULATE ( LASTDATE ( 'Table'[date] ), 'Table'[date] )
VAR _weekDay =
WEEKDAY ( _lastDay )
VAR _firstDayInLastWeek =
CALCULATE ( LASTDATE ( 'Table'[date] ) - _weekDay, ALL ( 'Table' ) )
VAR _lastWeek =
IF ( SELECTEDVALUE ( 'Table'[date] ) >= _firstDayInLastWeek, 1 )
RETURN
IF ( _lastWeek = 1, "light blue", "light Green" )
If this does not work, could you please share some sample data without sensitive information and expected output.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
Hi, @SantiagoRandado
Based on your description, I have created many measures to achieve the effect you are looking for. Following picture shows the effect of the display.
Steps:
Measures:
Color =
VAR _lastDay =
CALCULATE ( LASTDATE ( 'Table'[date] ), 'Table'[date] )
VAR _weekDay =
WEEKDAY ( _lastDay )
VAR _firstDayInLastWeek =
CALCULATE ( LASTDATE ( 'Table'[date] ) - _weekDay, ALL ( 'Table' ) )
VAR _lastWeek =
IF ( SELECTEDVALUE ( 'Table'[date] ) >= _firstDayInLastWeek, 1 )
RETURN
IF ( _lastWeek = 1, "light blue", "light Green" )
If this does not work, could you please share some sample data without sensitive information and expected output.
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data in the Power BI Forum
hi, @SantiagoRandado
try below measure as conditional formatting
measure =
var a = selectedvalue(calender[date])
var b = maxx(filter(calender,calender[date]=a),calender[week])
return
if(calender[week]=b,"#FFFF00","#008000")
and follow step in below link solution
Thanks Dangar, the meassure give me this message "A single value for column 'week' in table 'calender' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.". It is underline [week] inside the if. Do you know how to solve it?
Hi, @SantiagoRandado
measure =
var a = selectedvalue(calender[date])
var b = maxx(filter(calender,calender[date]=a),calender[week])
return
if(max(wcalender[week])=b,"#FFFF00","#008000")
@SantiagoRandado Looks like it is missing an aggregation:
measure =
var a = selectedvalue(calender[date])
var b = maxx(filter(calender,calender[date]=a),calender[week])
return
if(MAX(calender[week])=b,"#FFFF00","#008000")
Thanks for your help. but all weeks are #008000, also the last week shown un the graph
Hi, @SantiagoRandado
try below measure
and for conditional formatting follow this Link for steps of conditional formatting
max week color =
var a= CALCULATE(MAX(Sales[week]),ALLSELECTED('Table'))
return
IF(MAX('Table'[week nu])=a,"yellow","green")
download file from below link
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 18 | |
| 14 | |
| 7 | |
| 5 | |
| 5 |
| User | Count |
|---|---|
| 29 | |
| 18 | |
| 17 | |
| 11 | |
| 10 |