Dynamically generating all dates in a month in Crystal Reports - crystal-reports

I'd like to display dynamic columns at run time for each day in a given month.
Example:
If January then 31 columns will be displayed.
If February then 28 columns will be displayed.
If March then 31 columns will be displayed.
If April then 30 columns will be displayed. And so on.
How can I do this?

You have two challenges: creating the data and 'pivoting' it.
Most data warehouses contain a date-dimension table that you could query to get all of the dates for a given month and year. If you want something more dynamic, you might be able to adapt my DateRanges() function for this purpose.
The next challenge it to convert the rows to columns. Crystal Reports' cross-tab does this with ease, at the expense of some flexibility. I usually make use of the summarized-field's Display String formula to do fancy formatting.
You could also create 62 formula fields (31 for the labels and 31 for the data), place them on the canvas, and suppress the 29th - 31st fields as appropriate.
If this report is being generated by custom code (as opposed to being deployed in BusinessObjects Enterprise), you could use the Crystal Reports SDK to dynamically create the columns that you need.

Related

Compute rolling average across years while displaying data split by year

The dashboard in the linked workbook shows a table with sales split by year on the top. Below, there's a table with the rolling average of the last 4 weeks, including the current. It's set to show NULL if there are not enough data points. I'd like for it to compute the first January 2018 value based on the current week and 3 full weeks from the end of 2017. Carrying that concept forward, all NULLs from 2018 onward will be eliminated. The NULLs for the first 5 weeks of 2017 will be the only NULL values. The average should always be computed on a full 4 weeks (28 days) even when week 53 doesn't contain 7 days.
How can I write a calculation to achieve what's described above?
I've tried putting the WINDOW_AVG function inside a LOD, but that's not allowed. Furthermore, I've also tried using FIXED and even FIXED inside WINDOW_AVG.
Here's one of my attempts:
{FIXED [Week_int]:
WINDOW_AVG(SUM([Sales]), -4, 0)
}
It returns this error: "Error: Level of detail expressions cannot contain table calculations or the ATTR function"
Here's the data structure. It includes one value of Sales per day.
Basically I created a dummy data in Excel by creating dates (from 1-1-2017 to 2-2-2021) and filling some random values (unif dist *5000) against these.
I added Week[date] to columns and year[date] to rows as in your screenshot. I added sum(value) on the text marks card.
Thereafter, I added table calculation --> Moving average --> edited it for previous 4 values , next 0 values, (check current value if you want to include current record), then check Null if there are not enough values. (your requirement). --> click compute using -Specific Dimensions change the order of fields below - drag Year above than week (table across then down will also create the same view)
You should be able to get a view as desired.
Regarding your query on number of days in the week, Tableau caters it automatically if you have chosen it datepart.
Edit I verified this in Excel, the method is correctly working.
See, the average of first 28 values in Excel
and the view built in tableau:
Here's the corrected dashboard hosted on Tableau Public.

Tableau Running Sum doesn't calculate for all months

My data looks like this:
Month Profit($)
June 2018 100
In my Tableau Grid, I have setup a Running Sum table calculation (RUNNING_SUM(SUM([Profit]))) to project the cumulative profit until Dec 2018.
It doesn't work if the above is the only row in the underlying data! (I want the 100 to carry over to all the future months until Dec).
But it does work, if there is are rows until Dec 2018 in the underlying data.
(I don't want to add any kind of dummy rows in my underlying data because this is a very simplified scenario and my actual scenario is way too complex to add dummy rows.)
For this we doesn't have the direct solution.
for a workaround I have created an excel sheet having the details of all the Months in a Year and connected it with the current data set as a Full Outer join.
It will give you the date field in the Dimension pane of Tableau, use that in the columns Pane and Click on Show Missing Values.
You will get the desired results.

Jasper iReport Designer, weekly average

I am working with iReport Designer and want to ask how can I calculate an average sum of a column based on a date?
I am working on a report which has a database containing a table two columns: 1st is "sample_time" which has DATE values and the second is a "watt" which has an int value.
What I want to do is take the "watt" column and show it as average on the report (which I can do), and then show the same column "watt", but from averages based on the dates from the other "sample_time" column.
Lets say I have the dates from 2008-01-01 to 2008-01-20 and I want to do a weekly average, lets say from 01-01 to 01-07, how can I do that?
Well, i think this can get easily achieved using JasperReports Groups. You can create a group based on you sample_time column, and calculate the average for each group (which means, for each date, its just like doing a group by on a SQL query). Here there are two quick tutorials:
JasperReports Groups || The Groups

Crystal reports crosstabs column grouping

I'm trying to build a cross tab report in Crystal XI that has dates, grouped by the month as column heading, and have 2 questions I'm trying to find answers to.
1: Is there any way to display a month even if there are no records to be summarized in that month? i.e. no orders for March, but want to display Jan, Feb, Mar.? I'm pretty sure I can create a dates table and use that spoof it, but don't want to go that route as the database is part of a Vendor's package and I don't want to get to crazy in there.
2: Is there a way of specifying or limiting how many columns go across? For example in a forecast cross tab I only owant current month and the next six months to show up. I suppose I can do a date range on the selection criteria, but that seems a bit kludgy to me.
Thanks for any answers
Short answer: No.
I've seen discussions about workarounds involving creation of temporary tables, but I've never tried any such solutions myself.
I would go with the date range on the selection criteria. You could make those dates parameters for more convenient useage. If you have sevral cross-tabs that should have different date ranges you could put the crosstabs in sub-reports.

Crystal reports: using summary field in formula / summing time field in formula

In crystal reports I want to show the sum value of time objects, i.e. An employee worked in one month three days and on each day a variable amount of hours.
Is there anyway to sum a time field?
Or as a workaround I could use the time field as an integer, sum this and display. But then I would like to change the display format by using a formula. I cant find a way to include summary fields in a formula...
Thanks in advance
PS I am using CR 2011 (just the program not through VB or anything).
You cannot sum a date/time field. You will have to use datediff("n",{datetime1},{datetime2}) to get a time interval between two date/time fields in minutes.
To use a summary function in a formula, you can use this sum({#YourMinutesFormula},{FieldYouAreGroupingOn})
You may omit the second parameter if you want the summation over the entire report instead of a grouping level. Check the Crystal Reports help file for more details on Sum().