Cognos equivalent of Excel Sumif() function without a static variable - cognos

Here is the following example that I found that does work as a sumif function.
total(
case
when [free of charge flag] = 'FALSE'
then [Total Margin]
else null
end
for [Item Code])
My question is how to replace the 'FALSE' portion and have the expression reflect the [free of charge flag] for that specific row. So as the report builds the total in each row may switch from a total of that item code and the free of charge flag being false to true depending on what is in the specific row.
This fails to run and I believe this may not be possible.

You have [Item Code] as the column you are rolling up to but you can roll up to multiple columns.
Try this:
total([Total Margin] for [Item Code],[free of charge flag])
This will total the measure across all combinations of [Item Code] and [free of charge flag]. For a given [Item code] 'TRUE' and 'FALSE' rows will have their own values.
Further, if you don't want to show a total when the value is 'TRUE' then you can wrap this in a CASE statement:
CASE [free of charge flag]
WHEN 'FALSE' THEN total([Total Margin] for [Item Code],[free of charge flag])
ELSE NULL
END
All rows with 'FALSE' will show the total for that particular row's [Item Code] and all others will have NULL.

I think you can just derive it as a calculated column for each row:
(
case
when [free of charge flag] = 'FALSE'
then [Total Margin]
else null
end
)
And then just total that.

Related

How to assign calculations done in a for loop by row to blank columns by index?

I have a dataframe that looks like this (with more rows):
Buy Sell acct_stock usd_account
0 True False
1 False True
I assigned two numerical values to two variables like so:
account = 1000
stock_amount = 0
For each row in the df that has the combination of True AND False, I want to update columns acct_stock and usd_account by using the numerical variables to do calculations:
I have come up with the following FOR loop:
for index,row in df.iterrows():
if (row['Buy'] == True & row['Sell'] == False):
row['acct_stock'] = (account * 0.02)/row[4]
row['usd_account'] = account - (stock_amount * 0.02)
When I run this the columns acct_stock and usd_account do not get updated at all, even for rows where the conditions are met.
What am I doing wrong that the calculations are not being assigned by index to the columns/rows in question and the variables 'account' and 'stock_amount' are also being updated continously?
The answer of why is didn't work is included in this page, The code you need to look at is here
However keep in mind you need to have those column first before you can set a value

spotfire calculated column using over function

I want to create a calculated column "indicateur" that traces the boolean values
when I have a True, I increment the indicator by 1, however i want the false rows to have the value of the last true indicator.
and when i pass to a new ID, the incrementation starts from zero.
I already tried some spotfire expression using the over function but not getting the right results
case
when [boolean] then sum(If([boolean],1,0)) over (Intersect([ID],AllPrevious([ID])))
else 0
end
You have a couple of issues here. Your case statement is sub setting the data... it will only calculate sums where boolean is true.
The main issue is the over statement though. Something like this should give the correct answer
sum(If([boolean],1,0)) over (Intersect([ID],AllPrevious([Timestamp])))

saved search to pull date invoice was paid in full

I've a transaction saved search in which I've various formula columns displaying invoice date, any related credits, and then actual payments after any term discounts taken. Now I need to add another column to display the date invoice was marked "Paid in Full" I'm using the formula which is not working: case when {systemnotes.newvalue} = 'paid in full' then {systemnotes.date} end
I can't use 'date closed' because that's just displays the most recent payment date against an invoice and not the date it was fully applied for example an old credit memo.
Any input is appreciated.
Oracle string comparisons are case sensitive. {systemnotes.newvalue} returns 'Paid In Full' - not 'paid in full' (note the Title Case). You can correct the comparison to use Title Case like this:
case when {systemnotes.newvalue} = 'Paid In Full' then {systemnotes.date} end
or you can coerce both sides to upper or lower case for a slightly more robust comparison:
case when UPPER({systemnotes.newvalue}) = UPPER('paid in full') then {systemnotes.date} end
I've tested both of these and they work for me.
Why not just use the Date Closed? (closedate)

Excel Using AND and OR together on the IF function

I have a problem that I cant figure out how to solve. currently I am solving this in excel but eventually be using sql.
We have a survey which is meant to run when the billed amount reaches ;
•first trigger $50k, then $150, then $250.
Sample Data
'last run' is when the survey last ran and 'Current Value' is the current billed amount.
So for row 1 , the survey last ran when billed amount was 55000 and now it is 160000 which is greater than the threshold 150K so survey should run hence it should return 'true'.
Row 2 : is also true because current value is greater than 'last run and also 'is >= 150K
Row 3: is also true because it has passed the threshold of 150K
Row 4 : should return false because between last ran and current value there isn't any threshold passed.
If
CurrentValue >= Last Run
And Current Value >= 50K or 150K or 250K
then 'True' Else false
We are going to drive the survey Initiation from the true or false returned from this.
The data is only sample data , values for current and last run can change but the trigger amounts will remain the same.
any help would be appreciated.
I understand your question this way:
You want to calculate which trigger the last Run value was checked against, and which trigger the Current Value is checked against, and if they are different and the Current Value is greater than last Run then we need to run the survey again (return TRUE), otherwise we don't (return FALSE).
If the above understanding is incorrect, please let me know.
To calculate this I would simply build one IF-statement expression that determines which trigger that last Run used, and the same for Current Value, and compare them.
Here are the two formulas:
=IF(A2>=250000;3;IF(A2>=150000;2;IF(A2>=50000;1;0)))
=IF(B2>=250000;3;IF(B2>=150000;2;IF(B2>=50000;1;0)))
Then we need to put it all together, so here's the final formula:
=AND(
IF(A2>=250000;3;IF(A2>=150000;2;IF(A2>=50000;1;0)))
<>IF(B2>=250000;3;IF(B2>=150000;2;IF(B2>=50000;1;0)))
;B2>A2)
(remove linebreaks and put it all together on one long line)

Excel: Combining semi-duplicated records (with different columns)?

How would I combine records if specified columns are the same?
Here's what I have, and the result I'm looking for:
It can be done using array formulas if you don't mind them being big and ugly. This example should do what you're looking for. In case of duplicate entries, it simply takes the last defined value (Prog instead of Programmer for Kevin Moss):
Enter the following formula into C11 and D11, then press CTRL+SHIFT+ENTER to apply the array formula. You can then copy the formula to the rows below as needed.
=INDEX((IF((((($A11=$A$2:$A$7)+($B11=$B$2:$B$7))=2)+(C$2:C$7<>""))=2,C$2:C$7,"")),MAX(IF((IF((((($A11=$A$2:$A$7)+($B11=$B$2:$B$7))=2)+(C$2:C$7<>""))=2,C$2:C$7,""))<>"",ROW($A$1:$A$6),0)))
This breaks down what's happening a little bit, but admittedly it's still pretty opaque, sorry:
=INDEX(
(IF( # This IF statement collects all entries in a data field for a given Fname/Lname combination
(((($A11=$A$2:$A$7) + ($B11=$B$2:$B$7))=2) + (C$2:C$7<>""))=2, # Checks that First and Last Name Match, and Data field isn't empty
C$2:C$7, # Return data field if TRUE
"" # Return empty if FALSE
)),
MAX( # Take the highest index number, use it to select a row from the result of the IF statement above
IF(( # This IF statement returns an index number if the data field isn't empty
IF( # This IF statement collects all entries in a data field for a given Fname/Lname combination (copied from above)
(((($A11=$A$2:$A$7)+($B11=$B$2:$B$7))=2)+(C$2:C$7<>""))=2,
C$2:C$7,
"")
)<>"", # End of conditional statement
ROW($A$1:$A$6), # Value if TRUE (ROW used as an incrementing counter)
0 # Value if FALSE (0 will be ignored in the MAX function that uses this result)
)
)
)

Resources