Crystal reports formula Syntax - date

Need help to create a formula in crystal syntax(Crystal reports) to calculate number of days between two dates from WO_DATE.WO_DATE (WO = work order) where WO_DATE_TYPE.WO_DATE_TYPE_DESC = "START" and WO_DATE_TYPE.WO_DATE_TYPE_DESC = "Due".
Below is my DB Schema

In Crystal's database expert, add the WO_Date table twice. The 2nd instance would require an Alias (a different name).
Join to require the Work_Order_ID be the same across the two instances.
In the record selection formula, force the first instance to be the START type.
Similarly, force the second instance to be the END type.
Now, simply subtract the date in the first table instance from the date in the second table instance.

Related

SSAS Tabular - No relation between fact table and 2nd Date dimension

I have 2 date fields in my fact table start_date and end_date.
Fact table is connected to the dim date with start_date.
I need to slice data by the second date field so I've created another date dimension similar to the first dim date and connected the key to the end_date in the fact table, but for some reason there's no relation between them when I browse the cube.
I made sure the keys are in the same format, data type etc.
The new dim date is 'marked as date table'.
What am I missing?
Thanks a lot.
Try with TabularEditor:
https://github.com/otykier/TabularEditor/releases/tag/2.13.0
open your Model and check relationships if you don't see the one you want, you can just add a new one.
You can also create multiple relationships to the same table using different columns (but as inactive), you can use this inactive relationship in calculation using USERELATIONSHIP.

Microstrategy - AddDays

I need to be able to use the AddDays function to derive the last week from the date column that I have in the dataset.
So, I have delivery_date of 3/21/2018, then I want to derive AddDays('3/21/2018',-7.0) - only that I want to do do this for every row in the dataset. But, the AddDays function only takes a metric. Can you suggest how I can work around this situation?
Thank you in advance,
Abhilash
As usual it depends on what you want to achieve.
If you need an attribute that returns delivery_date - 7, just create a new attribute and in the definition of the expression you can put a formula like [delivery_date] - 7 or use a pass-through function like ApplySimple to write the formula for your database (more info here).
Note: If you do this, you need to do the form expression with the formula (or the ApplySimple) only for the forms mapped on the fact table, the forms mapped on the lookup table (your Day dimension table) should be without formula, otherwise parent level will returns wrong values. Also if you don't a lookup for this new attribute create an alias or enable -Attribute Role Recognization more here.
If you need to calculate metric values for delivery_date - 7, then in that case you need to use a transformation metric. You will need to create a minus 7 days or same day previous week transformation, then associate it to the Delivery Date attribute and create the needed metrics. The last week transformation is included in the MicroStrategy Tutorial project.

Joining two datasets to create a single tablix in report builder 3

I am attempting to join two datasets in to one tablix for a report. The second dataset requires a personID from the first dataset as its parameter.
If i preview this report only the first dataset is shown. but for my final result what i would like to happen is for each row of a student there is a rowgrouping (?) of that one students modules with their month to month attendance. Can this be done in report builder?
The best practice here is to do the join within one dataset (i.e. joining in SQL)
But in cases that you need data from two separate cubes(SSAS) the only way is the following:
Select the main dataset for the Tablix
Use the lookup function to lookup values from the second dataset like this:
=Lookup(Fields!ProductID.Value, Fields!ID.Value, Fields!Name.Value, "Product")
Note: The granularity of the second dataset must match the first one.
We had a similar issue and that can be resolved this way.
First of All, ensure the first data set's query and second data set's query are working fine by executing separately on the Database client tool such as Datastudio.
Build two data sets on SSRS tool with the respective queries and make sure both the data sets have same key column (personID).
On the SSRS report design, create a table from tool box and add the required columns from the first data set along with the matching key column(personID). Add a new column and use look up function to get the required column from the other data set against the same key column (personID).

SSRS 2008 - Multiple Groupings For Date Range

A record in a table contains a range of valid dates, say:
*tbl1.start_date* and *tbl1.end_date*. So to ensure I get all records that are valid for a specific date range, the selection logic is: <...> WHERE end_date >= #dtFrom AND start_date < #dtTo (the #dtTo parameter used in the SQL statement is actually the calculated next day of the *#prmDt_To* parameter used in the report).
Now in a report I need to count the number of records for each day within the specified data range and include the days, if any, for which there were no valid records. Thus a retrieved record may be counted in several different days. I can do it relatively easily with a recursive CTE within the data set, but my rule of thumb is to avoid the unnecessary load on the SQL database and instead return just the necessary raw data and let the Report engine handle groupings. So is there a means to do this within SSRS?
Thank you,
Sergey
You might be able to do something in SSRS with custom code, but I recommend against it. The place to do this is in the dataset. SSRS is not designed to fill in groups that don't exist in the dataset. That sounds like what you are trying to do: SSRS would need to create the groups for each date whether or not that date is in the dataset.
If you don't have a number or date table in your database, I would just create a recursive CTE with a record for every date in the range that you are interested as you mention. Then outer join this to your table and use COUNT(tbl1.start_date) to find the appropriate days. This shouldn't be too painful a query for SQL server.
If you really need to avoid the CTE, then I would create a date or number table to use to generate the dates in your range.

Crystal Reports. How do I show amount of records between 2 optional dates

I'm new to Crystal and I have to create a basic report that requires 2 input optional parameters: DateStart and DateEnd.
Report shall include amount of records in a table beetween 2 dates (if DateEnd date value is missed report shall consider that it requires all records no matter how old they are. If DateStart is missed report shall consider it requires all records no matter how young they are)
I guess I'll have to use SQL Expression Field but can't figure out how to implement where clause.
How would you implement such a report?
Thank you in advance!
Try this:
Create a Date Parameter with optional prompt and range.
Then i Record Selection Formula put:
if ( (not HasValue({?PARAM_YOUR_DATE}) or (not(HasLowerBound({?PARAM_YOUR_DATE}))) or (not(HasUpperBound({?PARAM_YOUR_DATE}))) ) then
True
else
{YOURDB.YOUR_DATE_FIELD} in {?PARAM_YOUR_DATE};
When you want to show all records add special value i.e. 01/01/1900
crParameterDiscreteValue.Value ="19000101";
In First Formula
{?DateStart} = '19000101' or {table.DateStart} = {?DateStart}
In Second Formula
{?DateEnd} = '19000101' or {table.DateEnd} = {?DateEnd}
no need to use if else statement.