crystal reports month date range for earnings - date

My client has a report that accepts a date range to get a report showing projected revenue. So, a user would enter a date range of '1/1/2015 to 1/31/2015' and the report should return data only in the range '1/1/2015 to 1/31/2015 grouped by week. I am instead for the week of 12/29/2014 (which 1/1/2015 fall into) and 2/1/2015 (which 1/31/2015 falls into). The report is intended to group by week, but I do not want days on the report that are earlier than the start date parameter or later than the end date parameter.
The sql statement for this report is:
SELECT job.job, job.status, job.customer_po, job.part_number, job.unit_price,
job.price_uofm, delivery.promiseddate, delivery.remaining_quantity, job.build_to_stock, job.description, job.make_quantity, job.pick_quantity, job.shipped_quantity, job.lead_days
FROM dbo.delivery as delivery RIGHT OUTER JOIN db.job as job on delivery.job = job.job
WHERE job.build_to_stock = 0 AND (job.status = 'active' OR job.status = 'hold' OR job.status = 'pending')
The date range is from this code and parameters:
Max – Maximum(?Date Range)
Min – Minimun(?Date Range)
Date Range - "From " & {#Min} & " to " & {#Max}
This is the group expression
Group 2 Name - GroupName ({#Adj Date 2}, "weekly") & " thru " & cdate(GroupName ({#Adj Date 2}, "weekly"))+6
This is the select expression
{#Date} = {?Date Range} and
not {Job.Build_To_Stock} and
{Job.Status} in ["Active", "Hold", "Pending"]
Do you know how I can prevent the "overflow" of dates outside of date range?
Thx

As long as you have date filtering in your record selection formula there will not be any "overflow" outside of that range. If you've got {Record.Date} in Minimum({?DateRange}) to Maximum({?DateRange}), which it sounds like you do, then your report will not contain any records outside of the parameter regardless of how you group them.
Your problem might stem from over-complicating or misinterpreting the grouping. All you need to do is group by {Record.Date} and select "Group by week" in the grouping options... you don't need any complicated formulas to break it out by week. But be aware that the way weeks are referred to is by their starting date. For example, if you had a record with a date of Feb. 19, 2015, that record would fall into the group labeled "Feb. 15, 2015" even if your {?DateRange} parameter was Feb. 18 - Feb. 15.

Related

Tableau: How do I convert date to month-week #?

I have a date column. For example, the date is 8/2/2022, I'm hoping to see that this will convert to Aug Week 1; and if let's say the date is 7/15/2022, then the result should say July Week 3.
Please help, thanks!
You need to use LOD to do so, as default, you can only do week numbers by year in tableau, you need to create two calculated field to do so:
1.Create a [Min-Week] calculation field as shown below:
{ FIXED MONTH([Date]):MIN(DATEPART('week',[Date]))}
Note the calculation above for [Min-Week] assumes that there is at least one record for the first week of each month. If your data does not allow you to rely on that assumption, you could instead use DATEPART('week', DATETRUNC('month', [Date]))
2.Create a [Week-By-Mth] calculation field as shown below :
CASE DATEPART('week',[Date]) WHEN [Min-Week] THEN "Week 1" WHEN [Min-Week]+1 THEN "Week 2" WHEN [Min-Week]+2 THEN "Week 3" WHEN [Min-Week]+3 THEN "Week 4" WHEN [Min-Week]+4 THEN "Week 5" WHEN [Min-Week]+5 THEN "Week 6" END
EDIT good answer - here's just a shorter equivalent expression for [Week-By-Mth]
"Week " + STR(DATEPART('week, [Date]) - [Min-Week] + 1)
If you prefer an integer to a string, you could simplify further by getting rid of the Week prefix and the STR() call.
The [Week-By-Mth] calculation field should be what you need.

How to count events after set date with COUNTIFS?

I'm creating this report in spreadsheet
https://docs.google.com/spreadsheets/d/1U48MybVshKT3eRYE9goRCab9k1KCoXe7Zsr9Ogkkm4Y/edit?usp=sharing
In "BD" you can find the records and in "NB-month" the KPI that I want to analyze; I would like to create DATE filter for the numbers in the columns, ex for the col: "nº Contract closed" I'm thinking to use this formula:
=COUNTIFS(BD!R:R;A5;BD!G:G;">"&DATE(B2))
but I get a value: "0" that is incorrect because for this agent "Carla Vaello" the number of contracts closed after 2020-02-01 should be "2".
your usage of DATE formula is wrong (DATE requires 3 parameters). either change DATE to DATEVALUE or use:
=COUNTIFS(BD!R:R; A5; BD!G:G; ">"&B2)

Unable to display view using two Parameters in Tableau

I have a "Select Year" Parameter for Year.
If I select from "Select Year", then I want to display results for Selected Year and Previous Year (both) in a CrossTab View on the same Sheet.
Please refer to attached to know more about my query.
*Other way (unwanted): *
I tried to create two Calculated Fields (Dimensions Filters for selecting the Year), then created two different sheets - "Selected Period Value" and "previous Period Value", but I want just one sheet to display it together.
//Selected Year
IF YEAR([Year]) = INT([Year Parameter]) THEN
INT([Year Parameter])
END
//Previous Year
IF YEAR([Year]) = INT([Year Parameter])-1 THEN
INT([Year Parameter])-1
END
Please assist.
Just assuming 46.34% and 46.85% as Profit measure.
Create two calculated fields, one for the year selected from parameter and the other for prior year.
Profit_Current calculated field:
IF YEAR([Year]) = INT([Year Parameter]) THEN Profit
ELSE 0 END
Profit_Previous calculated field:
IF YEAR([Year]) = INT([Year Parameter])-1 THEN Profit
ELSE 0 END
Use these two calculated fields in cross tab
Let us know if this works!

Calculate a Reference Date in DAX

Trying to nail down the syntax for a pretty straightforward problem.
I have a table called Events and a full-feature DATES table with a relationship between the Dates[Date] field.
Using the event name as a slicer, I trying to create a [First Monday] measure that will return the date of the first Monday of the month.
So for example, if my event date was 2/14/19, [First Monday] would return 2/4/19.
Your Date table needs to contain 2 columns:
Year-Month: for example, "2018-01"
Weekday Number: for example, 1 (for Monday); or Weekday Name (i.e, "Monday")
Then:
First Monday =
CALCULATE( MIN('Date'[Date]),
ALL('Date'),
VALUES('Date'[Year-Month]),
'Date'[Weekday Name] = "Monday")
How it works:
First, we need to access all dates in the Date table, so we use ALL()
Second, we need to see only dates for the current context year and month, for which we can use VALUES()
Third, for each month we only want Mondays, hence Date[Weekday] = "Monday"
All this unfiltering/filtering generates a set of Mondays for the Year-Month visible in the current filter context. All we need to do now is to find the earliest of the Mondays using Min(Date).

Check if the difference between dates is exactly 'n' months in expression SSRS

In my quarterly report Im trying to validate the two parameters StartDate and EndDate.
I first check if the difference between the dates is 2 months:
Switch(DateDiff(
DateInterval.Month, Parameters!StartDate.Value, Parameters!EndDate.Value) <> 2,
"Error message")
Then I try to add whether the StartDate is the first day of month AND EndDate is last day of month:
And (Day(Parameters!StartDate.Value) <> 1
And Day(DATEADD(DateInterval.Day,1,Parameters!EndDate.Value)))
So the whole expression looks like this:
Switch(DateDiff(DateInterval.Month, Parameters!StartDate.Value, Parameters!EndDate.Value) <> 2
And
Parameters!IsQuarterly.Value = true
And
Day(Parameters!StartDate.Value) <> 1
And
Day(DATEADD(DateInterval.Day,1,Parameters!EndDate.Value))<>1),
"Error: Quarterly report must include 3 months")
But It works wrong when the difference between dates is still 2 months, but StartDate and EndDate are not first and last day of the whole period.
I'd appreciate any help :)
I would say just change the implementation Add another two Parameter With Quarter and Year
Quarter like Q1,Q2,Q3 & Q4 with Value 1,2,3 & 4 respectively and year 2012,2013,2014 & so on
Now based on the parameter selected Qtr & Year set Default value of start & End Date
=DateSerial(Parameters!Year.Value), (3*Parameters!Qtr.Value)-2, 1) --First day of Quarter
=DateAdd("d",-1,DateAdd("q",1,Parameters!Year.Value, (3*Parameters!Qtr.Value)-2, 1))) --Last day of quarter
Doing this no need to do any validation bcz its always get the correct Date Difference.
Other Reference
First day of current quarter
=DateSerial(Year(Now()), (3*DatePart("q",Now()))-2, 1)
Last day of current quarter
=DateAdd("d",-1,DateAdd("q",1,DateSerial(Year(Now()), (3*DatePart("q",Now()))-2, 1)))