I am using Crystal Reports 2008 and cannot figure out the proper expression for suppressing fields.
In this case, say I have a pill diary.
{PILL.TYPE_ANTI_INFLAMMATORY}
{PILL.TYPE_PAIN_REDUCTION}
{#INTEGER_TYPE1}
{#INTEGER_TYPE2}
The first two elements from the data tables PILL are columns of pill types. The first one is a column of type of anti-inflammatory pills, the second pain reduction. These columns each contain unique information.
In the second two elements, is a column of integers either negative or positive. These are formula columns (date difference between two dates.)
My expression:
{PILL.TYPE_ANTI_INFLAMMATORY} = "Advil" or
{PILL.TYPE_PAIN_REDUCTION} in ["Tylenol", "Acetometaphin"] and
{#INTEGER_TYPE1} > 1 or
{#INTEGER_TYPE2} > 1
What I am trying to do is display any row in which ANTI_INFLAMMATORY is equal to Advil or PAIN_REDUCTION is equal to Tylenol or Acetometaphin while also one of the columns of integer type is greater than 1.
(
{PILL.TYPE_ANTI_INFLAMMATORY}="Advil" or
{PILL.TYPE_PAIN_REDUCTION} IN ["Tylenol","Acetometaphin"]
) and
(
{#INTEGER_TYPE1} > 1 or
{#INTEGER_TYPE2} > 1
)
IF ({PILL.TYPE_ANTI_INFLAMMATORY}="Advil" or {PILL.TYPE_PAIN_REDUCTION} IN ["Tylenol","Acetometaphin"])
AND
({#INTEGER_TYPE1} > 1 or {#INTEGER_TYPE2} > 1) THEN
FALSE ELSE TRUE
Related
I am trying to get a result in my report, which I beleive, requires a where clause and did not work for me with the select expert section.
I have 2 tables. Lets call them table 1 and table 2.
Table 1 contains unique records.
Table 2 contains multiple records for the same uniqueKey as table 1.
there are 3 fields in table 2 that play a roll for each uniqueKey from table 1.
QTY_ORD
QTY_SHIPPED
ITEM_CANCEL
Lets assume for item # 1 from table 1, there are 5 records in table 2. Each record has a values for the 3 above mentioned fields. I need to display the SUM of all the records where ITEM_CANCEL = 0 of QTY_SHIPPED - QTY_ORD.
It could be that 3 of the records have ITEM_CANCEL = 1 (We can ignore these records), but for the other 2 reocrds where ITEM_CANCEL = 0, I need the SUM of QTY_SHIPPED - SUM of QTY_ORD.
the current code I have is as follows"
if {current_order1.ITEM_CANCEL} = 0 then
sum({current_order1.QTY_ORD})-sum({current_order1.QTY_SHIPPED}) else
0
but this result gives me the sum of ALL the records, including the ones where ITEM_CANCEL = 1.
If I use ITEM_CANCEL = 0 in the select expert, then it removes ALL the results that have no value in table 2. I even tried the code without using the SUM function, but this provided the result of only 1 of the records in table 2 where ITEM_CANCEL = 0, and not the total difference of the 2 records in table 2 that I require.
Any suggestions on this?
Start with a detail-level formuls (no SUM):
if {current_order1.ITEM_CANCEL} = 0 then {current_order1.QTY_ORD} - {current_order1.QTY_SHIPPED} ELSE 0
Then, SUM that formula at whatever Group or Report levels you require.
Edited to provide sample data
I am trying to create a calculated column that sums 2 other columns, which should be easy. However, some values in both of the columns are null, so I want to use a case expression to replace null values in both columns with 0s and then add up the resulting values. The other complicating factor is that the second column contains text values with commas that need to be converted to numerical before I can add them. What I am currently trying to do is:
SELECT (case when pm."PS" is null then 0 else pm."PS" end) + (case when pm."PS-PREV1" is null then 0 else replace(pm."PS-PREV1", ',', '')::numeric end) AS "Sales"
FROM pm
Sample data:
PS
PS-PREV1
20000
null
30000
20,000
null
null
null
30,000
Desired output:
output
20000
50000
0
30000
This is just returning the value of the 1st column without adding in the second column. Where am I going wrong? Am I overthinking this?
your code should work , however you can write it a little bit more clean:
SELECT COALESCE(pm."PS",0)
+ COALESCE(replace(pm."PS-PREV1", ',', '')::numeric,0) AS "Sales"
FROM pm
I am looking for difference of two columns in Tableau. I have the formula with me.
IF ATTR([Valuation Profile]) = "Base" THEN
LOOKUP(ZN(SUM([Value])), 1) > - ZN(LOOKUP(SUM([Value]),0)) END
But I get it as a separate column in the columns sections. How do I get that in the rows section? Basically how to get the difference as a dimension?
Please see attached images of what I want and what I have. Apparently, I cannot upload my excel sheet and tableau worksheet here. So I have upload just the screenshots.
What I have - vs - What I want
Tableau Workbook
First off, there is no way that you can generate additional rows for your data in Tableau!
In your case however you could use a workaround and do the following:
Create a calculated field for BASE and one for CSA. The formula should
be IF [Valuation Profile] = 'BASE' THEN [Value] END and IF
[Valuation Profile] = 'CSA' THEN [Value] END respectively
Afterwards you can drag Measure Names onto your rows shelf and
replace the SUM([Value]) with your two newly created calculated fields
that should give you all three measures in different rows in your table
Reference: https://community.tableau.com/message/627171#627171
Use LOD expression to calculate the individual values first.
Create calculated fields 'BASE', 'CSA' and 'CSA-BASE' as below.
BASE:
{FIXED [Book Name]: SUM( if [Valuation Profile] = 'BASE' then Value else 0 end ) }
CSA:
{FIXED [Book Name]: SUM( if [Valuation Profile] = 'CSA' then Value else 0 end ) }
CSA-BASE
[CSA]-[BASE]
Solution
id datetime new_column datetime_rankx
1 12.01.2015 18:10:10 12.01.2015 18:10:10 1
2 03.12.2014 14:44:57 03.12.2014 14:44:57 1
2 21.11.2015 11:11:11 03.12.2014 14:44:57 2
3 01.01.2011 12:12:12 01.01.2011 12:12:12 1
3 02.02.2012 13:13:13 01.01.2011 12:12:12 2
3 03.03.2013 14:14:14 01.01.2011 12:12:12 3
I want to make new column, which will have minimum datetime value for each row in group by id.
How could I do it in Power BI desktop using DAX query?
Use this expression:
NewColumn =
CALCULATE(
MIN(
Table[datetime]),
FILTER(Table,Table[id]=EARLIER(Table[id])
)
)
In Power BI using a table with your data it will produce this:
UPDATE: Explanation and EARLIER function usage.
Basically, EARLIER function will give you access to values of different row context.
When you use CALCULATE function it creates a row context of the whole table, theoretically it iterates over every table row. The same happens when you use FILTER function it will iterate on the whole table and evaluate every row against the filter condition.
So far we have two row contexts, the row context created by CALCULATE and the row context created by FILTER. Note FILTER use the EARLIER to get access to the CALCULATE's row context. Having said that, in our case for every row in the outer (CALCULATE's row context) the FILTER returns a set of rows that correspond to the current id in the outer context.
If you have a programming background it could give you some sense. It is similar to a nested loop.
Hope this Python code points the main idea behind this:
outer_context = ['row1','row2','row3','row4']
inner_context = ['row1','row2','row3','row4']
for outer_row in outer_context:
for inner_row in inner_context:
if inner_row == outer_row: #this line is what the FILTER and EARLIER do
#Calculate the min datetime using the filtered rows
...
...
UPDATE 2: Adding a ranking column.
To get the desired rank you can use this expression:
RankColumn =
RANKX(
CALCULATETABLE(Table,ALLEXCEPT(Table,Table[id]))
,Table[datetime]
,Hoja1[datetime]
,1
)
This is the table with the rank column:
Let me know if this helps.
I'vre created a cross tab report with 2 calculated Member to be able to have the difference between 2 column and the percentage of this difference in CR 2011. What I want to achieve is to create a new column that will display a test depending on the difference value.
Here is a example:
Col1 Col2 Difference Percentage Action
200 0 -200 100 DROPPED
100 100 0 0
0 300 300 100 ADDED
How can create this action column. Calculated member only want some amount value so I cannot output a text in the formula.
Thanks in advance for your help
I finally found the solution.
I can use the Display string formula in the Format Field properties (Common Tab). Here I just check the column and return the string I want otherwise I just format the number.
IF GetColumnGroupIndexOf(CurrentColumnIndex) = 1
AND CurrentColumnIndex =4 THEN
IF GridValueAt(CurrentRowIndex, CurrentColumnIndex,CurrentSummaryIndex) =2 THEN "DROPPED"
ELSE "ADDED"
ELSE
ToText( GridValueAt(CurrentRowIndex, CurrentColumnIndex,CurrentSummaryIndex),2,",")