on 02-13-2018 6:56 PM
Hi all, I'm working on a report that is grouping by month. I'm working on having the user to be able to select either to group by month or week. so here's what I have so far.
I created a groupby parameter type is "string" and values "static" and values are "week" and "month"
then i created a formula group:
______________________________
If {?GroupBy} = "Week" Then
//week:
dateadd("ww",datepart("ww",{table}, crMonday)-1,
date(year({table}),1,1)-dayofweek(date(year({table}),1,1),crMonday)+1)
Else
//month:
Right("00" & cstr(month({table}),0),2) & "/" & cstr(year({table}),0,"")
_______________________
so to me that looks good and make sense 🙂
but when i try to save and close the formula, an error message comes up that highlights the whole month formula and says "A date-time is required here."
any idea what am I doing wrong here?
Thanks in advance.
Use sort in Report Designer, right click Group and select Change group set sort order there.
Ian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Karim,
Modify the formula to:
if {?GroupBy} = "Week" then
totext(dateadd("ww",datepart("ww",{Date}, crMonday)-1,
date(year({Date}),1,1)-dayofweek(date(year({Date}),1,1),crMonday)+1))
else
totext(date(year({Date}), month({Date}), 01))
-Abhilash
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you Ian for the response but the group field that is in the "Record Sort Expert" is not sorting right. When I choose "Month" the sort is correct but when choosing "Week" the sort is all over the place. Also, in the Record Sort Expert, it does not allow me to remove the group field or choose to sort Asc or Desc. They are grayed out.
I have also tried crDescendingOrder at the end of the Week formula but that gave an error message:
The remaining text does not appear to be part of the formula.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Karim,
Get rid of the datatype conversion for the date fields in the code and that should fix the sort:
if {?GroupBy} = "Week" then
(dateadd("ww",datepart("ww",{Date}, crMonday)-1,date(year({Date}),1,1)-dayofweek(date(year({Date}),1,1),crMonday)+1))
else
(date(year({Date}), month({Date}),01))
-Abhilash
I assume your month format is 20180201 , 20180101.
As text this will sort correctly, whereas weeks are 1, 2, 3...11, 12,13 these will not sort correctly as text, change your week totext formula to
totext(dateadd("ww",datepart("ww",{Date}, crMonday)-1,date(year({Date}),1,1)-dayofweek(date(year({Date}),1,1),crMonday)+1), "00", 0, "")
This will format weeks a 01, 02, 03...11, 12, 13 which will sort correctly.
Ian
when I used
(dateadd("ww",datepart("ww",{Date}, crMonday)-1,date(year({Date}),1,1)-dayofweek(date(year({Date}),1,1),crMonday)+1))
it says a date-time is required here. >>> after the elseand when I used
totext(dateadd("ww",datepart("ww",{Date}, crMonday)-1,date(year({Date}),1,1)-dayofweek(date(year({Date}),1,1),crMonday)+1), "00", 0, "")
it highlighted "totext" and says "A string is required here."
and my date format is M/D/YYYY.
Not sure what am I missing!!!
Hi Karim,
This should hopefully work:
if{?GroupBy}="Week" then
Date(dateadd("ww",datepart("ww",{Date}, crMonday)-1,date(year({Date}),1,1)-dayofweek(date(year({Date}),1,1),crMonday)+1))
else
(date(year({Date}), month({Date}),01))
One more question, how can I sort ascending or descending for the group "week"? I tried crAscendingOrder but that did not work, it gives me this error: "The remaining test does not appear to be part of the formula."
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.