If you are unable to create a new account, please email support@bspsoftware.com

 

Need help with date_expression, _day_of_week, & conditional formatting

Started by vitraille, 15 Dec 2014 03:42:15 PM

Previous topic - Next topic

vitraille

I have a report with a date field.
I need to identify if the date is a weekday, or weekend.
If it is a weekday I need to format the date field to highlight a color, i.e. yellow, in that row's date.

The date field is: [Data].[Transaction Records].[Date - Start Date]
When I run the report the date returns: i.e. 12/8/2014.
Do I need to convert this to a date format i.e. MM/DD/YYYY?
If so, how do I do that?

Once I convert the date to a date expression do I use
"_day_of_week ( date_expression, integer )",
i.e.: _day_of_week  ( 01/01/2014, 3)   [Data].[Transaction Records].[Date - Start Date]
The reports earliest date is Jan. 1, 2014 which was a Wednesday.

I've created a data item called "Week Day", which is also a column in the report next to the "Date-Start Date" column.
1) If the "Date-Start Date" is a weekday then I want the "Weekday" column to return "Week Day".
2) If the "Date-Start Date" is a weekend date then I want the "Weekday" column to return "Weekend".
3) If the "Date-Start Date" is a weekday then I want the "Date-Start Date" row to turn a color, i.e. yellow.

Any help writing the statements and where to put them would be appreciated.
Many thanks,
Marcie

Lynn

You need to figure out if your date field is already a date data type or not. If you create a data item with this expression you can see if it complains about the data type or not.

_day_of_week ( [Data].[Transaction Records].[Date - Start Date], 1 )

If all is OK with the data type, next you need to understand the day of week function. It doesn't really matter what your earliest date is or what day of week that was. The integer argument simply defines what day of the week you want to be called "1". So the argument 1 says that your day 1 of the week is a Monday and your weekend days are, therefore, going to be 6 and 7.

You can wrap your day of week expression in a case statement to display the label you want. Use that for your conditional style on the date. I like advanced conditional styles myself, but there are different ways to tackle that depending on your preference.

case
  when _day_of_week ( [Data].[Transaction Records].[Date - Start Date], 1 )  >= 6 then 'Weekend'
  else 'Weekday'
end

Hope this gets you started.

vitraille

Thank you Lynn, your code worked great.
Sorry for the delayed reply...I thought I had written a thank you in December.
Leah