Total Average Week using a Parameter - crystal-reports

I have a crystal report that shows sales volumes called week to date volume. It shows current week, previous week, and average week. The report prompts for a date parameter and I extract the week number to get current week and previous week volumes. Did it this way because Mngmt wants to be able to run report whenever. My problem is for Average Week I cant figure out how to get the number of weeks to divide by for my average. Report originates from June 1st, 2010. Right now I have:
DATEPART("ww", {?date}) - DATEPART("ww", DATE(2010, 6, 1))
This returns 2 right now which is perfect, so i divide my total by 2. This code will work until the end of the year then I'm hooped. Any idea how I can make this a little more dynamic. I was thinking a counter somehow, just can't get the logic down because the date parameter will keep changing, meaning I cant increase my counter by 1 after each week???
Cheers.

Look into the Crystal Reports method: DateDiff.

Related

Tableau Function - Dates (Day)

I am looking for a tableau formula that would help me create a field that assigns what day number it is in the year. If I use format options the day number restarts every month in the year... I have also tried to create my own formula however it is counting all the days numerically however it does not restart the count after the year ends. I have provided the Formula below:
DATEDIFF('day',DATE('1900-01-01'), [Date: ReportDate]) + 1
I have tried changing the format of the date and I have tried creating a formula to count days and have failed at both :(
Try using : DATEPART('dayofyear', [date])
Assuming you are in a year filtered on 2022, try applying AVG()

How do we calculate difference and percent difference between two columns in tableau

]Difference and percent Difference must be calculated.
I cannot do Apr20-MAy20 because it is not always the same. I need to show the current month and previous month
So I did a relative filter to just show the current month and previous month.
So the difference of two columns should automatically change when the month changes.
Now how do I get the same month of prior year, how do I filter ?
I also need to calculate the difference of current year same month and previous year same month.
Thank you in advance for any help!
When I do table across difference, the difference value is overwriting the existing May and Apr month values as the below screen shot, how to show the difference in another column
Currently:
Below is Expected:
Sounds like you should create a custom filter for the dates. You want:
This month this year
This month last year
Last month this year
There are a number of ways you could do this. I'll give one example and will assume there aren't any future dates in your data set.
[DateFilter]: DATETRUNC('month',[YourDateField])>=DATETRUNC('month',DATEADD('month',-1,TODAY())) OR DATETRUNC('month',[YourDateField])=DATETRUNC('month',DATEADD('year',-1,TODAY()))
Put the to the filters shelf, set to True, and it should keep the months you want.
Then you can just use the standard table calculations to calculate Difference and Percent Difference.
Note, the formula isn't tested, just typed directly into here, let me know if it doesn't work
Based on your comments look at creating separate calculations for to YoY / MoM / etc calculation. That also means creating calculated fields to isolate the Current Month, Previous Month, etc.
For example, the current month:
[isCM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',TODAY())
The previous month:
[isPM]: DATETRUNC('month',[YourDateField]) = DATETRUNC('month',DATEADD('month',-1,TODAY()))
Then month on month, something like:
[MoM]: (SUM([Measure])*INT([isCM]))/(SUM([Measure])*INT([isPM]))
To make your table check this article about using the placeholder technique to create tables in Tableau

how to count week number of month using dataprep

I tried to count week number of month using below code,but I got weird num like -48.(I know my logic is weird lol)
Could you point out the fault of below code to make weeknum of month.
I need sensei's help.
I used Dataprep
WEEKNUM(date)-WEEKNUM(DATE(YEAR(date),MONTH(date),1))
no error , but some values are -48,47......
Your logic is mostly sound, except you're only thinking of WEEKNUM in the context of a single year. In order to have non-overlapping weeks, the week containing January 1 is always week 1 (regardless of the period), so in this case December 29–31, 2019 are all going to be week 1, just like the following 4 days of January will be. It makes sense, but only when you think about it in context of multiple years.
You can work around this for your case by checking the WEEKNUM and MONTH values conditionally, and then outputting a different value:
IF(AND(MONTH(date) == 12,WEEKNUM(date) == 1),53,WEEKNUM(date)) - WEEKNUM(DATE(YEAR(date),MONTH(date),1))
While hard-coding the week number of 53 is a little hacky, the whole point of week numbers is to always have 52 subdivisions—so I don't really see any concerns there.
You may also want to add 1 to the resulting formula (unless you want your week numbers to start with 0 each month).

Altering x-axis for dates in Tableau

I have a data set that has dates for many years. I can easily filter the data by month or week, but I was hoping to change the X axis to make it start in October and end in April.
Is there a way to do this in Tableau without altering the original data and listed dates?
I don't know about it ending in April since that would not be a full 12 months but you can make it start in October. Right click on your date field > Default Properties > Fiscal Year Start. Then select October.

Crystal report formula syntax

I have a report I am trying to modify in Crystal. It has a data field that has a formula in it, but I want to use another formula.
This is an example of what I am trying to do.
[((# Days in January) – 15) x (Market Rent/(# Days in January))]
+ [((# Days in February) – 0) x (Market Rent/(# Days in February))]
+ [14 x (Market Rent/(# Days in March))]
I have ADO commands built out for the market rent, and a start date and end date. The months in my example are just that an example. I am not sure how to take my ADO command dates that are entered in on a filter page, and put them in a formula like the one above. Any ideas?
Also, in the first and last para. the -15 and the 14 are for a date in the middle of the month. So if the start date was on the 15th of Jan, and the End date was the 15th of march. This formula would calculate my loss of rent during vacancy.
If I'm reading your question correctly, you want to take a date field and find out how to measure the number of days in that month, the month before it, and the month after it. Here's some Crystal formulas to help you out. Let's assume your date field is called {#DateFld}:
To find the number of days in a particular month relative to a particular date, try this:
local datevar X:=cdate(dateadd("m",0,{#DateFld}));
datediff(
"d",
date(year(X),month(X),1),
date(year(X),month(X)+1,1)
)
I recommend you copy & paste this in 3 different formulas:
- In the 1st formula, replace the "0" with a -1 to get the number of days in the previous month.
- In the 2nd formula, don't change anything. That'll get you the number of days in the current month (i.e. the month that {#DateFld} is in)
- In the 3rd formula, replace the "0" with a +1 to get the number of days in the next month.
For example, if {#DateFld} is March 10th, 2011, the 1st formula will give you 28, the 2nd will give you 31, and the 3rd will give you 30.