How can I adjust the cross tab order using a formula in Crystal Reports - crystal-reports

I am trying to organize my cross tab labels in a specified order. The table shows students that have left the school by grade level and year. Grade level is dependant on an if - then formula because the database does not have the grade that students left the school. The grade level is calculated by subtracting the withdrawal year from their grad year and then applying a text string based on the result.
When I try to adjust to a specific order there is no option to select the individual groupings as my formula is not available in the common tab. The labels in the column are accurate but just out of order.
Any help would be greatly appreciated. I am fairly new to Crystal reports. Perhaps I am not understanding how a cross tab works or perhaps there are problems with my formula.
current view of order
Cross tab expert view

Easiest solution is to change the formula that generates the labels so they sort alphabetically as you wish. You can pad the numbers with a zero so that '1' becomes '01' or prepend the text with a counter (01., 02., etc.).

Related

Displaying change in moving average on map

I am trying to show the change in moving average by county on a map.
Currently, I have the calculated field for this:
IF ISNULL(LOOKUP(SUM([Covid Count]),-14)) THEN NULL ELSE
WINDOW_AVG(SUM([Covid Count]), -7, 0)-WINDOW_AVG(SUM([Covid Count]), -14, -7)
END
This works in creating a line graph where I filter the dates to only include 15 consecutive dates. This results in one point with the correct change in average.
I would like this to number to be plotted on a map but it says there are just null values.
The formula is only one part of defining a table calculation (a class of calculations performed client side tableau taking the aggregate query results returned from the data source)
Equally critical are the dimensions in play on the view to determine the level of detail of the query, and the instructions you provide to tell Tableau how to slice up or layout the query results before applying the table calc formula. This critical step is known as setting the “partitioning and addressing” for the table calc, sometimes also as setting the “compute using”. Read about it in the online help for table calcs. You can experiment with using the Edit Table Calc dialog by clicking on the corresponding pill.
In short, you probably have to a dimension, such as your Date field to some shelf - likely the detail shelf, and the set the partitioning and addressing, probably to partition by county and address by state.
If you have more than a couple of weeks of data, then you’ll get multiple marks per county. You may need to decide how to handle that on your map.

Tableau - Comparing one against an average of many on same worksheet

I'm looking to compare a single Fortune 500 company's revenues (selected by the end user from a list of all Fortune 500 companies) to an average revenue for all Fortune 500 companies over time. I would like the averages to show up as bars and the single company revenues to show as a line graph (both on the same chart).
I understand how to set two different chart types on the same view. What I don't understand is how to write the calculations and parameters to give the end user the functionality of choosing a single company and comparing it against all others.
Any suggestions on how to do this? Happy to clarify further if needed.
Thank you in advance!
I don't have Tableau right now to test, but I believe that kind of chart can be achieved using 2 measures.
Well, you need to create the measures then. The average of all is pretty straight forward, it's AVG(Revenue).
The single company revenue can be retrieved using parameters. Create a parameter like [Company chosen], and put the list of all Fortune 500 (you can load from field, which helps a lot).
Then create a calculated field [Company revenue]:
IF [Company] = [Company chosen]
THEN [Revenue]
END
And just use the sum or avg of this measure.
Put both the measures on the worksheet and set the right chart
I am using the superstore data that ships with Tableau.
You can create an LOD calculation to calculate the average:
SUM({FIXED [Order Date (Months)] : SUM([Sales])}) / SUM( {COUNTD([Sub-Category])})
This is calculating the total sales at each month and summing the sales and then dividing that by the number of points for each month (thereby giving you an average of sales per month).
FYI, I submitted this question to Tableau. They replied with a workbook using the Superstore data with the following instructions:
Add Year(Order Date) to the column.
Add Sales to the row.
Create a parameter called Select Country with the following settings:
Name: Select Country
Data Type: String
Allowable Values: List
Add from field: Country/Region
Select OK.
After creating the parameter, Right Click on the parameter in the data pane and select Show Parameter Control.
Create a calculated field Country Sale called with the following formula:
IF [Country / Region] = [Select Country] THEN [Sales] END
Add Country Sale to the Rows Shelf.
Go to Sum(Country Sale) tab on the Marks Pane and select Line from the drop down.
Right Click on the Country Sales axis and select Dual Axis.
Right Click on the Country Sales axis and select Synchronize Axis.

Aggregating ratios in Crystal Reports pivot table

Simple pivot table:
In this case, I'm pulling back 5 fields from the database:
Category
Year
Quarter
Numerator
Divisor
2 unfortunate facts. First, the year/quarters drift to provide a rolling 8-quarter view. Consequently, there will usually be 1 full year and 2 partials with their respective quarters. Second, the measures to be displayed are ratios of numerator to divisor. Naturally, Crystal is assuming that I want to divide everything and then total it, which is not correct.
How do you get the pivot table totals to calculate correctly as SUM({Numerator})/SUM({Denominator})? Since there are multiple levels in play, the Sum({Numerator}, {Attribute})/Sum({Denominator}, {Attribute}) doesn't seem to work or I'm missing an extra element to it.
This crosstab is intended to replace a report that individually calculated every cell, and is not viable for long-term maintenance. If the totals can't be corrected, we'll have to revert back to that format.
Once you create a cross tab... you can insert saperate column or row inside the existing column using the option embeeded summary
Right click---> Embeeded Summary ---> insert embeeded summary
This will insert a row as Edit This Formula.
Now on the newly created cell
Right click---> Embeeded Summary ---> Edit Calculation formula
This will open a window there write your division formula.

Require minimum number of data points before plotting a point in Tableau

Can I cause Tableau to require a certain number of underlying data points before plotting a point on the graph?
For example, here's a graph showing average moods over the course of the day on Tuesdays:
There's nothing uniquely awful about midnight on Tuesdays, it's just that there's only one data point for that particular time, and it's an outlier. Is it possible to have the graph show midnight as missing unless there are more than (for example) three different records from midnight being averaged together?
You could define an aggregate calculated field, called say avg_mood as:
if count(Mood) >= 3 then avg(Mood) end
Since the aggregation is hard coded into the calculation, Tableau will display AGG(avg_mood) for the field on any shelves you use it on, rather than letting you toggle the aggregation outside the formula as it will for other measures.
Note, there is no else branch, so the calculation will evaluate to null if there are less than three non-null Moods in a partition of data rows (based on the dimensions)
You can control how null values are displayed in a line chart. On the format pane, select the field in question from the pull down menu by the word Fields at the top right of the format pane, then select the Pane tab, then at the bottom of the format pane, adjust the Mark settings in the Special value section.

Adding Reference Line for Weighted Average in Tableau

I've got a bar chart with three months worth of data. Each column in the chart is one month's data showing the percentage of Rows that met a certain criterion for that month. In the first month, 100% of 2 rows meet the measure. In the second month, 24.2% of 641 rows meet the measure. In the 3rd month, 28.3% of 1004 rows meet the measure. My reference line which is supposed to show the average across the entire time-frame is showing 50.8%, the simple average (i.e. [100+24.2+28.3]/3) instead of the weighted average (i.e. [100*2+641*24.2+1004*28.3]/[2+641+1004]).
In the rows shelf, I have a measure called "% that meet the criterion", this is defined as SUM([Criterion])/SUM([NUMBER OF RECORDS])
The criterion measure is 1 for any record that qualifies and null for any that do not qualify.
If I go to Analysis >> Totals >> Show Row Grand Totals, a 4th bar is added, and that bar shows the correct weighted average of the other three bars (26.8%), but I really want this to be shown as a reference line instead of having an extra bar on the chart. (Adding the Grand Total bar also drops the reference line down to 44.8%, which is the simple average of the 4 bars now shown on the chart--I can't think of a less useful piece of information than that).
How can I add the weighted average as a reference line?
Instead of using 'Average' as your aggregation, try using 'Total' instead in the Edit Reference Line dialogue window.
I have to say it's a bit counter-intuitive, but this is what the Tableau online help has to say about it:
http://onlinehelp.tableau.com/current/pro/online/mac/en-us/reflines_addlines.html
Total - places a line at the aggregate of all the values in either the cell, pane, or the entire view. This option is particularly useful when computing a weighted average rather than an average of averages. It is also useful when working with a calculation with a custom aggregation. The total is computed using the underlying data and behaves the same as selecting one of the totals option the Analysis menu.
If you are using Tableau 9, you can make second calculated field using an LOD expression
{ SUM([Criterion]) / SUM([NUMBER OF RECORDS]) }
This will calculate the ratio for the entire data set after applying context and data source filters, without partitioning the data by any of the other dimensions in your view (such as month in your case)
If you place that new field on the detail shelf then you can use it to create a reference line.
There are other ways to generate a weighted average, but this is probably the simplest in your case.