I have a dimdate table that is represented below. I have each day flagged as BusinessDay Y/N. I also have a DimSalesRep table that has a daily goal for each rep. I want to be able to allow users to input a StartDt and EndDt with filters on the report and have a calculated column look at the business days between those dates. I can calculate daysbetween with defined dates but I am unsure how I would use DAX with variable dates that are applied through Report filters.
I should also note I am not sure how best to handle a startdt and enddt filter based of the column, TheDate
Cheers!
Reference your dimdate table twice
StartDate = 'dimdate'
EndDate = 'dimdate'
and use this measure:
Num BusinessDays =
CALCULATE(
COUNTROWS('dimdate'),
'dimdate'[BusinessDay] = "Y",
'dimdate'[Date] >= SELECTEDVALUE(StartDate[Date]),
'dimdate'[Date] <= SELECTEDVALUE(EndDate[Date])
)
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!
Hi I'm new in crystal reporting, i would like to make percentage for annual year growth based current year with the previous year.
For example, I would like to check the growth for CMP4 for current year (2017) and previous year (2016).
CMP_vc_Code,InvYear,Jan,Feb,Mar,Apr,May,June,July,Aug,Sep,Oct,Nov,Dec
CMP1,2016,0,0,318.50,68.25,91,182,338,195.25,140.70,0,117.25,0
CMP2,2017,550.30,0,0,0,0,0,0,0,0,0,0,0
CMP3,2017,160.95,0,0,0,0,0,0,0,0,0,0,0
CMP4,2016,3226.90,13141,13131.40,5108.60,4148,5529.60,1082.25,12945.85,5002.30,2239.80,4035.40,4454.35
CMP4,2017,13362.85,8671.35,10233,0,0,0,0,0,0,0,0,0
I have details of the company sales (row data) which is given to the crystal report. So In crystal report, I first group by data based on year and company. Total of each month is generated dynamic using crystal report sum field. Please help me on this.
This should be close to what you are looking for...
1) Make sure your data is grouped be year. (Which it sounds like you are)
2) Insert a SUM summary in the year group footer. (Also sounds good just make sure its in the group footer)
3) Use a formula like this...
Global CurrencyVar b := IF GroupNumber = 1 THEN Sum ({TableName.DollarAmount}, {TableName.Year}) ELSE b;
Global CurrencyVar e := Sum ({TableName.DollarAmount}, {TableName.Year});
Local NumberVar p := IF b = e OR b = 0 THEN 0 ELSE ((e - b) / b * 100); // or whatever calculation you are using...
b := Sum ({TableName.DollarAmount}, {TableName.Year});
p
4) Place the formula field in the group footer, next to the SUM from step #2.
I have a dataset of dates. It has just one column CreatedOnDate and its values are in datetime as shown below.
This dataset has 6 months of values as shown. I have a parameter called Report Type which has possible values Monthly, Weekly, Daily (Screenshot below)
I have created a calculated field (called Created On Date) which converts the date based on Report Type selected. The formula is shown below
CASE [Report Type]
WHEN "Monthly" THEN DATENAME('month', [CreatedOnDate])
WHEN "Weekly" THEN "Week " + STR(DATEPART('week',[CreatedOnDate]))
WHEN "Daily" THEN STR(MONTH([CreatedOnDate])) + "/" + STR(DAY([CreatedOnDate])) + "/" + STR(YEAR([CreatedOnDate]))
END
This works perfectly. The result of the calculated field is shown below.
I now need to incorporate the following logic
IFF Report Type = "Daily" Display only the last 30 days in the dataset
Other cases Show all values
How do I achieve this?
woodhead92, I'd suggest using so called Level of Detail expressions that were introduced in Tableau v8. First create a calculated field that will calculate the most recent (=MAX) date available:
{FIXED : MAX(CreatedOnDate) }
Let's call this MaxDate LOD. Then adding a new calculated field Show/Hide:
IF [Report Type] = "Daily" AND
([CreatedOnDate] >= DATEADD('day', -30, [MaxDate LOD]) THEN 'Show'
ELSEIF [Report Type] = "Weekly" OR [Report Type] = "Monthly" THEN 'Show'
ELSE 'Hide'
END
Add this filter and select 'Show' value only. I am assuming that you want to see all dates when Weekly/Monthly date granularity is selected - if that's not the case, simply add more ELSEIF conditions.
The formula above could be simplified, but I wanted to make it as verbose as possible so that it helps you understand how Level of Detail expressions work.
One thing to keep in mind - FIXED LOD calculation overwrites filters, so if you have a date-range filter available, you will have to make sure it's added to context. More details on filter context are available here in this a bit out-dated, but still excellent blog post.
Create a calculated field for your condition and then place it on the filter shelf to include only rows that evaluate to true.
[Report Date] <> "Daily" or
datediff('day', [CreatedOnDate], { max[CreatedOnDate] } < 30
The Curley braces are significant, an LOD calculation
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.