Forum Discussion
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?
- Anonymous2 years ago
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 TeamIf 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
7 Replies
- Dangar332Resident Rockstar
hi, SantiagoRandado
try below measure as conditional formattingmeasure = 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
- SantiagoRandadoNew Member
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?
- Dangar332Resident Rockstar
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")
- AnonymousNot 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.
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 TeamIf 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