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
SantiagoRandado
New Member

Help With DAX Meassure

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? 

 

SantiagoRandado_0-1706884011289.png

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

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.

 

vyaningymsft_0-1707117821281.png

 

Steps:

vyaningymsft_6-1707117924391.png

vyaningymsft_2-1707117821286.png

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

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

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.

 

vyaningymsft_0-1707117821281.png

 

Steps:

vyaningymsft_6-1707117924391.png

vyaningymsft_2-1707117821286.png

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

Dangar332
Super User
Super User

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

conditional formatting 

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")


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...

@Greg_Deckler @Dangar332 

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")

 

Dangar332_0-1706952234213.png

 

download file from below link

Help with Dax measure 

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.