I'm developing a Report Server on SSRS 2005. In this report there are some clause contracts. Just one of this clauses isn't constant, so sometimes it appears and sometimes doesn't. It will appear if a column value on one of my datasets isn't null,
Every clause must be preceeded by a char and a Parentheses. For example, the first clause must be preceeded by a), the second by b), the third by c)...
The problem is, that clause that can be shown or not, if shown, must be the clause a and the other constant clauses must follow it. But if the variable clause doesn't appear, the first constant clause must be the a clause.
I tought the following. On the sql code of my dataset I made a case when test to check the column that indicates if the clause will appear or not, if it's null, the clause will not appear and I return on the select of my dataset the integer value 96, if it is not null, the clause will appear and I return on the select of my dataset the integer value 97.
I want to convert this integer value to a char. So 97 will become an a.
I'm using the report server element TextBox to receive this integer value, so I want to do somenthing like this.
=Convert.ToChar(First(Fields!FIRSTLETTER.Value, "DataSetAditionalInformation"))
I use Convert.ToChar(value) in C#, and I want to know the equivalent command to use on my Report Server.
On the first constant clause on my report I want to do the following:
=Convert.ToChar(First(Fields!FIRSTLETTER.Value + 1, "DataSetAditionalInformation"))
And for each constant clause, I will increase by one the number after the plus signal.
So, if the variable clause appears, the FIRSTLETTER will be 97, and the second clause will be 98, after converting these number will become the letters a and b. If the variable clause doesn't appear, the FIRSTLETTER will be 96, and the first and constant clause will be 97, and after converting: a.
I don't even know if this is possible, so any idea will be appreciated to solve this problem.
Thanks in advance.
UPDATE
A example of how the contract clauses will work:
I have this select:
SELECT CASE WHEN ADDITIONAL_CLAUSE IS NULL THEN 96 ELSE 97 END AS FIRST_LETTER,
ADDITIONAL_CLAUSE
FROM TBLADDITIONALDATA
WHERE (NUMBER_CONTRACT = #NUMBER_CONTRACT)
If the select returns 96 (and this means that there isn't an additional clause), the clauses will be like below:
a) The amount of monthly contemplations will be defined in accord to the disponibility of the credit of the group on the respective month of the Meeting Group realization.
b) The total amount of plots are not constants, because them are calculated in accord with the variation of the object price
If the select returns 97 (and this means that there is an additional clause), the clauses will be like below:
a) The text of this clause isn't constant, it depends of the value stored in the column ADDITIONAL_CLAUSE
b) The amount of monthly contemplations will be defined in accord to the disponibility of the credit of the group on the respective month of the Meeting Group realization.
c) The total amount of plots are not constants, because them are calculated in accord with the variation of the object price
I have a lot of other constant clauses, but I guess they are not necessary to exemplify.
So I need to make the letters that preeceed the clauses be not constant, so every letter will be a text box.
The textbox of the additional clause will just appear if the ADDITIONAL_CLAUSE isn't null, this I already did on the Visibility Expression of the textbox. And this textbox receives the value of FIRST_LETTER.
But the other textboxes of every constant clauses will receive the value of FIRST_LETTER plus 1 for the first constant clause, plus 2 for the second constant clause, plus 3 for the third constant clause and so on. But the value of FIRST_LETTER is an integer, so I need to convert it to char.
Thanks again.
Related
I'm trying to order a group in Crystal Reports 2016, with a value that should be shown at the end of the group.
For example, these are the values (strings) from the group:
B
A
C
D
E
I want to put "C" at the end and the rest ascending, like this:
A
B
D
E
C
My SQL expression is already sorting it in the desired order, but that doesn't work.
I tried it with "Specified Order", but the value C would be the first record.
Also the formula on Groupoptions for sorting with checkbox "Use Formula for Groupordering.." doesn't work for me, because i can't even select the databasefield...
(I'm using the german version of crystal reports, the exact description of the elements may be different)
How could i get this to work?
If your query already returns the correct order , just use "in original order." instead of specified
This is the data that comes back from the database
Data Sample for one season (the report returns values for two):
What you can see is groupings, by Season, Theater then Performance number and lastly we have the revenue and ticket columns.
The SSRS Report Has three levels of groupings. Pkg (another ID that groups the below), venue -- the venue column and perf_desc -- the description column linked tot he perf_no.
Looks like this --
What I need to do is take the revenue column (a unique value) for each Performance and return it in a separate column -- so i use this formula.
sum(Max(Fields!perf_tix.Value, "perf_desc"))
This works great, gives me the total unique value for each performance -- and sums them up by the pkg level.
The catch is when i need to pull the data out by season.
I created a separate column looks like this
it's yellow because it's invisible and is referenced elsewhere. But the expression is if the Season value = to the Parameter (passed season value) -- then basically pull the sum of each of the tix values and sum them up. This also works great on the lower line - the line where the grouping exists for pkg -- light blue in my case.
=iif(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
However, the line above -- the parent/header line its giving me the sum of the two seasons values. Basically adding it all up. This is not what I want and also why is it doing this. The season value is not equal to the passed parameter for the second season value so why is it adding it to the grouped value.
How do I fix this??
Since your aggregate function is inside your IIF function, only the first record in your dataset is being evaluated. If the first one matches the parameter, all records would be included.
This might work:
=IIF(Fields!season.Value = Parameters!season.Value, Sum(Max(Fields!perf_tix.Value, "perf_desc")), 0)
It might be better if your report was also grouping on the Venue, otherwise you count may include all values.
In Tableau, what are the rules when it comes to adding 2 statements if you cannot put everything in 1? In the first part of the statement below, I am trying to pull all products besides 1 of them from a distributor, then in the part I am trying to pull all the units except from 2 of the distributors. However, as you can guess, the cells are blank when I drag the pill over.
Is it best practice to just create 2 calculated fields and add THOSE together?
(IF [Distributor] = "NDC"
AND [Product] <> "PE Single Use"
THEN ['15] END)
+
(IF [Distributor] <> "NDC"
AND [Distributor] <> "M&D"
THEN ['15] END)
Here are a few simple rules about calculations in Tableau (and generally in SQL also)
If you don't specify a value in some case, say by leaving off the else clause in an if statement, the expression evaluates to null in that case. That can be fine or a problem depending on what you want. Consider null to mean no-value, or not-applicable or missing-value depending on your situation.
Nulls propagate through other expressions. A null value + anything yields a null value. You can explicitly test for null if necessary, but it is often better to keep simple expressions that evaluate to null when any part is null.
Aggregation functions like SUM(), MIN(), AVG() etc silently ignore null values. So AVG(Salary) is really the average of all the rows that had a non-null value in the Salary field. You don't get any warning about this, it is understood. If you want to know how many rows have a non-null value for a field, you can use the COUNT() function to check.
In your expression above, the two IF conditions are never both true for the same record. So at least one of the two halves of your expression is null in each case, so the resulting entire expression is always null.
There are other rules to learn when using table calcs and LOD calcs, but these rules apply throughout.
I want to calculate the difference between the previous and the current column and make it a new column named increase. For this, I'm using the lag window function. The value of the first column is not defined since no previous column exists. I know that a 3rd parameter specifies the default value. However, it depends. For the first row, I want to use the value of another column e.g. the one of count from that current row. This assumes that 0 is increased to count for the first row which is what I need. Specifying the column name as 3rd argument for the lag function does not work correctly and neither does using 0. How can it be done? I'm getting strange results such as quite a random result or even negative numbers.
SELECT *, mycount - lag(mycount, 1) OVER (ORDER BY id, messtime ASC) AS increase FROM measurements;
Window functions cannot be nested either:
ERROR: window function calls cannot be nested
There is another issue with your query: So far your results are in random order, so you may think you are seeing problems that don't exist.
Add ORDER BY id, messtime to your query to see the rows in order. Now you can compare one row with its predecessor directly. Are there still issues? If so, which exactly?
SELECT *, "count" - lag("count", 1) OVER (ORDER BY id, messtime) AS increase
FROM measurements
ORDER BY id, messtime;
COUNT is a reserved word in SQL. It seems the DBMS thinks you want to nest COUNT and LAG somehow.
Use another column name or use quotes for the column:
SELECT *, "count" - lag("count", 1) OVER
From every references that I search how to do cumulative sum / running total. they said it's better using windows function, so I did
select grandtotal,sum(grandtotal)over(order by agentname) from call
but I realize that the results are okay as long as the value of each rows are different. Here is the result :
Is There anyway to fix this?
You might want to review the documentation on window specifications (which is here). The default is "range between" which defines the range by the values in the row. You want "rows between":
select grandtotal,
sum(grandtotal) over (order by agentname rows between unbounded preceding and current row)
from call;
Alternatively, you could include an id column in the sort to guarantee uniqueness and not have to deal with the issue of equal key values.