Need a calculated column to pull value from previous row, different column, when NULL, use previous value - calculated-columns

Spotfire rookie here.
i'm trying to populate a calculated column with a value from another calculated column.
The goal is to populate the [my_row_id] with [my_first_reading] and where [my_first_reading] is NULL.
The code below is populating all of the NULL's from [my_first_reading] as 1 as shown in the image below.
calculated column
the code for above is:
If([my_first_reading] is not NULL ,[my_first_reading],First([row_id] ))
Any help appreciated.

solved:
Parm
first_read
ID
start
1
1
read2
1
read3
1
start
2
2
read2
2
first_read:
case
when Find("start",[Parm])>0 then RowId()
else NULL
END
ID: LastValidBefore([first_read])
struggled with this for a while. found a similar approach on the forum.
let me know if you have a better solution. thanks!

Related

How to reproduce the equivalent of a Countif excel function in Business Objects?

I'm from France (sorry for my english) and I am currently working on the latest version of Business Objects (business-intelligence suite from SAP).
I would like to transpose an Excel formula to Business Objects, but I cannot. Could someone be able to answer me how to reproduce the equivalent of a Countif function, please ?
In my example, I have a whole list of repeating social security numbers to which I have appended a variable number taken from another field. I would like to do a count for each security number and know how many of them have the "2" value attached to them in my other field.
Example :
For 1741111111100 | 17411111111001, the result in a new field will be 2.
For 1741111111100 | 17411111111001, the result in a new field will be 2.
For 1741111111100 | 17411111111002, the result in a new field will be 2.
For 1741111111100 | 17411111111002, the result in a new field will be 2.
For 1741111111100 | 17411111111003, the result in a new field will be 2.
For 1751111111100 | 17511111111001, the result in a new field will be 1.
For 1751111111100 | 17511111111002, the result in a new field will be 1.
For 1751111111100 | 17511111111003, the result in a new field will be 1.
For 1761111111100 | 17611111111001, the result in a new field will be 0.
For 1761111111100 | 17611111111001, the result in a new field will be 0.
For 1761111111100 | 17611111111003, the result in a new field will be 0.
In excel it's easy to do with a Countif function but how could I do this in Business Objects, please ?
Thank you in advance because I spent a whole afternoon in vain.
RE-EDIT
Here's the same example with excel :
1741111111100|1|17411111111001|2|
1741111111100|1|17411111111001|2|
1741111111100|2|17411111111002|2|
1741111111100|2|17411111111002|2|
1741111111100|3|17411111111003|2|
1751111111100|1|17511111111001|1|
1751111111100|2|17511111111002|1|
1751111111100|3|17511111111003|1|
1761111111100|1|17611111111001|0|
1761111111100|1|17611111111001|0|
1761111111100|3|17611111111003|0|
A column :
there are my security numbers (1741111111100 repeated 5 times, 1751111111100 repeated 3 times, 1761111111100 repeated 3 times)
B column :
It's a number between 1 and 3.
C column :
I concatenated A column + B column like =CONCATENATE(A1;B1)
D column :
Here are my countif functions done like this :
=COUNTIF(C$1:C$11;CONCATENATE(A1;"2")) that gives a quantity of "2".
=COUNTIF(C$1:C$11;CONCATENATE(A2;"2")) that gives a quantity of "2".
=COUNTIF(C$1:C$11;CONCATENATE(A3;"2")) that gives a quantity of "2".
=COUNTIF(C$1:C$11;CONCATENATE(A4;"2")) that gives a quantity of "2".
=COUNTIF(C$1:C$11;CONCATENATE(A5;"2")) that gives a quantity of "2".
=COUNTIF(C$1:C$11;CONCATENATE(A6;"2")) that gives a quantity of "1".
=COUNTIF(C$1:C$11;CONCATENATE(A7;"2")) that gives a quantity of "1".
=COUNTIF(C$1:C$11;CONCATENATE(A8;"2")) that gives a quantity of "1".
=COUNTIF(C$1:C$11;CONCATENATE(A9;"2")) that gives a quantity of "0".
=COUNTIF(C$1:C$11;CONCATENATE(A10;"2")) that gives a quantity of "0".
=COUNTIF(C$1:C$11;CONCATENATE(A11;"2")) that gives a quantity of "0".
I was interested by the "2" value attached to the security number and the number of security numbers concerned by this attachment.
So, it's easy to do with excel but so so so hard to do with B.I. !
Thanx for any help.
Background:
Context Operators:
ForEach
ForAll
In
Operate on "Sets" of data allowing you to parse out data into subsets and aggregate. in SQL this is similar to "Over Partition By" if you're familiar with it.
Answer:
If we assume you create a variable in the report [Concat] as follows:
=Concatenation([A];"2")
Then we can use formula:
=Sum(If([C]=[Concat];1;0)) ForEach([Concat]) In ([C])
Where [C] is your concatenated columns A+B.
Explanation
The above essentially says if [C] = [Concat] return a 1 otherwise return a 0 and then sum the results of those evaluations together.
This occurs ForEach unique value within [Concat]; found in [C].
Logically the system finds all the unique values in [Concat] in then iterates though [C] evaluating if [C]=[Concat] for each case. it then sums the results for each [concat] and then renders those results for each [C]
Additional Point:
In my example the report data was being "combined" due to duplicate values So row 1, row 2 in your example were combined. I had to turn off BO's combining of this row data or my results were skewed. This can be accomplished by formatting the result table and checking the top checkbox "Avoid Duplicate row Aggregation" If you have other values which make each row unique, you will not have this problem. You can turn this off at a query level as well in the query properties of the edit data provider. I believe it depends on what source you use as to which method must be used... But I'm not positive.
So below you can see results from [Cnt] match your expected results in column D using the aforementioned formula.

Create a text cell value based on row entries and corresponding columns

I understand this is a tough way of wording the problem I have. Please try and help me.
I want to create a Column called Orders which contains cells based on corresponding item values.
So if I have columns: FlatNo, Truffle, Pineapple, Mango, Chocochips; I want to create a column called Orders which has value:
FlatNo - A51
Mango - 1
Chocochips - 1
(if no values in the Pineapple & Truffle Columns, none show up in Orders columns)
See image
How do I do that ? Thank you in advance
You can use IF and &. & simply puts the different desired things altogether.
Hope the following formula will get you the result for column orders. I have put the number of each item ordered inside parentheses before the item.
="Flat No. "&A2&IF(ISBLANK(B2),"","-("&B2&")"&$B$1)&IF(ISBLANK(C2),"","-("&C2&")"&$C$1)&IF(ISBLANK(D2),"","-("&D2&")"&$D$1)&IF(ISBLANK(E2),"","-("&E2&")"&$E$1)
For instance the third order is shown like this: Flat No. E-23-(1)Truffle -1 Pc Rs 60-(3)Mango -1 Pc Rs 60

Iterate in column for specific value and insert 1 if found or 0 if not found in new column python

I have a DataFrame as shown in the attached image. My columns of interest are fgr and fgr1. As you can see, they both contain values corresponding to years.
I want to iterate in the the two columns and for any value present, I want 1 if the value is present or else 0.
For example, in fgr the first value is 2028. So, the first row in column 2028 will have a value 1 and all other columns have value 0.
I tried using lookup but I did not succeed. So, any pointers will be really helpful.
Example dataframe
Data:
Data file in Excel
This fill do you job. You can use for loops aswell but I think this approach will be faster.
df["Matched"] = df["fgr"].isin(df["fgr1"])*1
Basically you check if values from one are in anoter column and if they are, you get True or False. You then multiply by 1 to get 1 and 0 instead of True or False.
From this answer
Not the most efficient, but should work for your case(time consuming if large dataset)
s = df.reset_index().melt(['index','fgr','fgr1'])
s['value'] = s.variable.eq(s.fgr.str[:4]).astype(int)
s['value2'] = s.variable.eq(s.fgr1.str[:4]).astype(int)
s['final'] = np.where(s['value']+s['value2'] > 0,1,0)
yourdf = s.pivot_table(index=['index','fgr','fgr1'],columns = 'variable',values='final',aggfunc='first').reset_index(level=[1,2])
yourdf

Remove rows from data frame for which column equals one of following vectors

I have a data frame with 2 columns x&y.
Now I want to remove all rows where column x is either equal 1 or 3.
How can I do that?
setting rm<-c(1,3)
and then df<-df[!df$x==rm,] does not work
df<-data.frame(c(1,2,3,4,4,4,4,2,2,3,3),c(1:11))
rm<-c(1,3)
df<-df[!df$x==rm,]
Found an answer. So just in case anybody checks this question later on:
df<-df[ ! df$x %in% rm, ]

Excel: Countifs on Multiple Columns and Only on Visible Rows (Filtering)

I've seen several forum posts with the answer to this question, but I can't really understand how it's supposed to work, so I figured I'd come here for an explanation.
I have three columns:
CITY........|.Attribute 1.|.Attribute 2.|
Chicago..|........1........|........1........|
Chicago..|........1........|..................|
Boston....|........1........|........1........|
Chicago..|..................|..................|
Boston....|..................|..................|
Boston....|..................|........1........|
Chicago..|........1........|........1........|
Chicago..|........1........|........1........|
I want to get a count of the number of times a city has a "1" in Attribute 1 and Attribute 2. Normally, you would use COUNTIFS (=COUNTIFS(B2:B9,"1",C2:C9,"1"))which would give you the value of 4 - Rows 2, 4, 8, and 9.
But I want to be able to filter this list on the fly, and only be able to see data for Chicago rows, for instance. And thus, want to see the value of 3 - Rows 2, 8, and 9. But when the data is filtered, I still get the value of 4.
What code do I need to insert into my cell to get the value of 3 after filtering my list to only show Chicago, if I want to see when a city has a "1" in both Attribute 1 and Attribute 2?
Thanks!
Would this not work for Chicago?:
=COUNTIFS(A2:A9, "Chicago", B2:B9,"1", C2:C9, "1")
This would not require you to filter the data.
A variant of this could be used:
SUMPRODUCT((Attribute 1.=Satisfactory)*(SUBTOTAL(103,OFFSET(AW3,ROW(tblStudentProgress[D3 Activity])-MIN(ROW(tblStudentProgress[D3 Activity])),0))))
You could also create a helper column and sum attributes 1 and 2. If your helper column row equals 2 then you know both attributes exist. You could take this one step further and use concatenate to combine "Chicago" and your sum. And then filter by Chicago2.

Resources