Decimal places on dates, Crystal Reports - crystal-reports-2013

Good morning,
I'm currently working on a custom date for a label. It needs to read the last 2 numbers of the current year, followed by the number of day it is within the current year (8/3/2016 would be day 216). So if I were to print a label, the date on 8/3/2016 should read 16216. The following is the current code in the formula:
toText(CurrentDate,"yy") & DateDiff ("d", #1/1#, today) + 1
For reasons I'm unfamiliar with, this returns 16216.00. My question is how do I get rid of the decimal places with this being a text field?
If taken by themselves, toText(CurrentDate,"yy" returns 16 and DateDiff ("d", #1/1#, today) + 1 does return 216. It's only when concatenated that the decimal places appear. Is there a better way to do this?
I'm fairly new to using Crystal, so any help would be appreciated.
Thanks, guys.

You are looking for the Julian date. You have a couple of options
SELECT DATEPART(yy, #date), DATEPART(dy, #date)
SELECT RIGHT(CAST(DATEPART(yy, #date) AS char(4)),2)
The link below goes into much further detail
http://blogs.msmvps.com/robfarley/2009/03/25/converting-to-and-from-julian-format-in-t-sql/

Related

Power BI - Calculate Difference between previous day volume and the next day volume

I have got a table that only contains two column Legend (for Dates) and EOD Volume (for volume) as shown below.
I need to calculate the difference between the previous date volume. For example to calculate the difference between Feb 29 to March 2nd, it will be ((1469-1877) / 1469) * 100%. How to do create this measure in power BI. And the data also contains weekends and weekdays and i will need the analysis for all dates regardless of weekends and/or weekdays. Could someone please help me on this. Thank you in advance.
My propose solution works in a table at day granularity. Additionally, to handle working day the best-practice is to manage it as a binary attribute in the back-end because working days differ country by country so there is no standard dynamic way to handle them.
Possible Solution:=
VAR _YESTERDAY = CALCULATE(MAX('Fact'[EOD Volume]), PREVIOUSDAY('Calendar'[CalendarKey]))
VAR _TODAY = CALCULATE(MAX('Fact'[EOD Volume]))
RETURN
DIVIDE(_TODAY - _YESTERDAY, ABS(_YESTERDAY))

Can I generate the number of business days in a month in Visual Studio?

I have a report that takes sales data from a few tables. I want to add a field that will divide the total sales for the given month by the total number of business days in that same month. Is there a way I can calculate that in an expression? Do I need to create a new table in the database specifically for months and their number of business days? How should I go about this?
Thank you
Intuitively, I would say that you need a simple function and a table.
The table is to host the exceptions like Independence day, labor day, etc.
The function will get two parameters: Month and Year (I'm not providing any sample code since you haven't specified which language you are using).
It will then build a date as yyyy-mm-01 (meaning, first day of the month). If will then loop from 2 to 31 and:
Create a new date by adding the index of the loop to the initial date,
Check if the resulting date is still within the month,
Check if it is a working or not working day (e.g. Sunday),
Check if it is found within the table of exceptions.
If the created date passes all the above tests, you add 1 to the counter.
Though it might look complex, it is not and it will provide you the correct answer regardless of the month (e.g. Feb.) and the year (leap or not).

Retrieve data based on current ISO week and backwards

I have to work with data retrieved and grouped on a weekly basis (ISO week) and my DB is structured on a daily basis (field: DATE). I need to write down a code which is rolling, so that given the current date, it calculate the week and the retrieve data in the previous 3 weeks, too.
So I write in the WHERE clauses:
TO_DATE(TO_CHAR(DATE, 'YYYYWW')) BETWEEN TO_DATE(TO_CHAR(TO_DATE(running_date, 'YYYYMMDD'), 'YYYYWW'), 'YYYYWW')-3 AND TO_DATE(TO_CHAR(TO_DATE(running_date, 'YYYYMMDD'), 'YYYYWW'), 'YYYYWW')
It doesn't seems to work though.
Any suggestions on how to handle the problem?
Thanks a lot!
You have to subtract 21 days when you want to recive the previous 3 weeks. If you subtract 3 then you recive only the last three days.
You need to use 'IW', not 'WW' as the format mask for ISO week. From the Oracle docs:
IW = Week of year (1-52 or 1-53) based on the ISO standard.
WW = Week of year (1-53) where week 1 starts on the first day of the year and
continues to the seventh day of the year.

Converting month names to actual months

Sorry for the odd title, not sure how else to summarize the issue.
I'm working with Report Designer 1.0 in SSRS 2005.
I have month names (e.g. January, February, etc) that I have extracted from a longer string that I am using in a 'Month' column of a table using this in the Edit Expression box:
=Mid(Fields!DESCRIPTION.Value, InStrRev(Fields!DESCRIPTION.Value, " ") + 1)
I now need to put the months in chronological order. Can anyone help?
Many thanks,
Jens

Subtracting between two dates for total days

i have three columns for Date In, Date Out, Total Days. If in Date In: 8/1/2011 and Date Out: 8/12/2011 Then the Total Days would be: 11 days. If Date Out is empty then Total Days = Current Date - Date In.
Problem: i cout get the total days if Date out is empty and using current date just fine, but getting total between date out and date in is giving me an error.
In the textbox in the reportviewer i have this expression:
=IIf(Fields!DateOut.Value=" "," ",Fields!TotalDays.Value)
The TotalDays is Current Date - Date In which i calculate in a stored procedure and just return the results.
I was thing of doing this but still i am getting an #Error in the textbox if i tried subtracting between date out and in if they are not empty.
=IIf(Fields!DateOut.Value=" ",DateDiff("d",Fields!DateOut.Value,Fields!DateIn.Value),Fields!TotalDays.Value)
Any suggestions.... Thanks
I know this is a little late, but i came up with the same issue. Here's what I did:
=CDate(Fields!DateOut.Value).Subtract(Fields!DateIn.Value).Days
Hope this helps!
Thanks for the info. Just wanted to share as I am not a programmer and this might be helpful to someone who is in my shoes that is required to write code.
I was able to create my formula from Answer 1. I had a requirement to have the Period End Date display the date 6 days prior. IE. EndDate = 06/24/2012 Field needs to display as 06/18/2012
=(CDate(Fields!EndDate.Value).AddDays(-6))

Resources