Number of Successive Cells of a Same Value in Spotfire - calculated-columns

I am wondering if it is possible to created a calculated column that will count how many cells of the same value are successive (i.e., next to each other) so that I can divide it by the total number of cells in that column. (I'm only looking at 1's and 0's in the column. Any help or advice would be greatly appreciated as I've been scratching my head over this for a while,
The percentages at the bottom of the columns is simply = (the number of 1's touching another 1) / (total # of rows) --> my end goal

Ok this has to be done in a few steps.
Insert a calculated column RowId() and name it rid
Insert a calculated column with this expression, and name it [TouchingA]:
If(([Location A]=1) and (([Location A]=First([Location A]) over
(Next([rid]))) or ([Location A]=First([Location A]) over
(Previous([rid])))),1,0)
Insert a calculated column with this expression, and name it [TouchingB]:
If(([Site B]=1) and (([Site B]=First([Site B]) over (Next([rid]))) or
([Site B]=First([Site B]) over (Previous([rid])))),1,0)
At this point, your data will look like this:
Next, insert a CROSS TABLE and set the Horizontal Axis = (Column Names), the Vertical Axis = (None), and the Cell Values = Sum([TouchingA]) / Max([rid]) as [A Percent],
Sum([TouchingB]) / Max([rid]) as [B Percent]
This will show you the values you want, like below. Of course you can sett his in a calculated value in a text area or anywhere else you want with the proper IF or CASE statement. Lastly, you can change the formatting to make the value a % versus decimal.

Related

How to find the 3 highest values and respective category for a cell

Here is an example of the data I'm trying to organize:
I'm looking for a way to automatically see the top 3 categories (column) for each Name# (row). The size of the category is determined by the number below the category.
Ideally, I'd also like to see a percentage breakdown (from the total) for each category. For example, in row "Name3" 2 categories make up a significantly larger portion of the total values. However, without this percentage breakdown, the 3 top values would seem to be comparable, when they are in fact, not.
Interested to see how this would all work with duplicate numbers, too.
I've tried Excel's rank function, but this doesn't tell me the categories that have the 3 largest sizes, just the 3 highest values.
With Office 365:
=FILTER(SORTBY($B$1:$H$1,B2:H2,-1),SORT(B2:H2,1,-1,TRUE)>=LARGE(B2:H2,3))
And copy down.
If there are ties it will expand the results to include it. It finds the third highest value and returns everything that is equal to or greater than it.
This approach spills all the results at once (array version). In cell J2, you can put the following formula:
=LET(D, A1:H5, A, TAKE(D,,1), DROP(REDUCE("", DROP(A,1), LAMBDA(ac,aa,
VSTACK(ac, TAKE(SORT(DROP(FILTER(D, (A=aa) + (A="")),,1),2,-1,1),1,3)))),1))
It assumes as per input data the cell A1 is empty (if not it can be adjusted accordingly). Here is the output:
An alternative that doesn't require previous assumption (but it is not really a hard one) is the following:
=LET(names, A2:A5, Data, B2:H5, colors, B1:H1, DROP(REDUCE("", names,
LAMBDA(ac,n, VSTACK(ac, TAKE(SORT(VSTACK(colors, INDEX(Data, XMATCH(n,names),0))
,2,-1,TRUE),1,3)))),1))
The non-array version can be obtained from previous approach, and expand it down:
=TAKE(SORT(VSTACK($B$1:$H$1,INDEX($B$2:$H$5, XMATCH(A2,$A$2:$A$5),0)),2,-1,TRUE),1,3)
Explanation
To spill the entire solution it uses DROP/REDUCE/VSTACK pattern. Check my answer to the following question: how to transform a table in Excel from vertical to horizontal but with different length.
For the first formula we filter for a given element of A name (aa) via FILTER the input data (D) to select rows where the name is empty (to consider the header) OR (plus (+) condition) the name is equal to aa. We remove via DROP the first column of the filter result (names column). Next we SORT by the second row (the first rows are the colors) in descending order (-1) by column (last input parameter of SORT we can use TRUE or 1). Finally, we use TAKE to take the first three columns and the first row.
For the second approach, we select the values for a given row (names equals n) and use INDEX to select the entire row (column index 0), then we form an array via VSTACK to add as first row the colors and use the similar logic as in previous approach for sorting and select the corresponding rows and column (colors).
Notes:
If you don't have VSTACK function available, then you can replace it as follow: CHOOSE({1;2}, arr1,arr2) and substitute arr1, arr2, wit the corresponding arrays.
In the second formula instead of INDEX/XMATCH you can use: DROP(FILTER(Data, names=n),,1), it is a matter of personal preference.

Function to search for specific number and then to further search for the prefix

I have a huge amount of data to process in which 4 points with a related prefix needs to be subtracted from each other.
Data consists of ID and x value
Example
ID = 290.12, 290.03, 290.06, 290.09, 300.12, 300.03, 300.06, 300.09, 301.12, 301.03, 301.06, 301.09
(let's call prefix a "ring number" and suffix time on the clock)
X value = any numerical value for each ID assigned
What I'm hoping to do is to search for the first number before the dot i.e. 300 and then subtract the value of 300.06-300.12 in one cell and in another cell 300.03-300.09.
(The subtraction is just an example, how I need to manipulate with the numbers is slightly more complicated, but I got this one under control)
This is my actual Data and what I need to produce is to the right of the raw data. At the moment, I'm doing it manually for each set of "rings"
Anyone knows how to approach this? I'm thinking vlookup, but I'm not very proficient in excel.
New Excel
I tried vlookup, but I don't know how to construct the formula and I run out of ideas.
Edit:
I found out that REDUCE is no requirement in this case, so it can be shortened to:
=SQRT(SUM(((INDEX(B:D,XMATCH(I3+0.09,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(I3+0.03,A:A),SEQUENCE(1,3)))^2)))
You could change +0.09 and +0.03 to your needs and may reference them using LET() for easy maintaining:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
SQRT(SUM(((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2))))
Previous answer:
=LET(
id,I3,
_id1,0.09,
_id2,0.03,
SQRT(
REDUCE(0, SEQUENCE(1,3),
LAMBDA(x, y,
x+((INDEX(B:D,XMATCH(id+_id1,A:A),y)
-INDEX(B:D,XMATCH(id+_id2,A:A),y))
^2)))))
This formula looks for the matching value of the id value I3 + _id1 minus the matching value of id value + _id2 for columns B to D and adds the ^2 results per column. Then it calculates it's square root.
You can change _id1 and _id2 to your needs.
To calculate the Delta (as shown) at once you could use:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
_id3,0.12,
_id4,0.06,
x,SQRT(SUM((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2)),
y,SQRT(SUM((INDEX(B:D,XMATCH(id+_id3,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id4,A:A),SEQUENCE(1,3)))^2)),
(x-y)*1000)
You can have a column of unique values of the integers and a new column where you reference these values as id and drag down the formula to get your row by row result
In another column you can refer to these columns and sort per the second column using SORTBY()

How can I find in Excel the last column where the value is different than in the prior column?

I have many rows with measurements that progress from left to right with the rightmost measurement being the most recent one. Often the values become zero at some point and stay zero until the end.
I am trying to find the last column where a change happened. I tried a lot but could not figure it out. In the first example (row 2) this would be column V (=column with the heading 18) where the value is -1.60 and no further values are available. In the second example (row 3) this would be column P (heading 12) and so on. In order to find this last-change column I have three steps (columns A, B, C) and a check (column D) to see if there are indeed no more non-zero values afterwards. This works well in many cases but it does not work if there is a zero value and then non-zero values before it is all zero to the end (rows 6 and 7). As there are in my case many columns (up to 270) it should be a general formula.
I would love to attach the sample Excel but I think this is not possible here. I did however paste the data part (E1:W7) as a csv here example data as csv, hope that is ok. Here the four formulas for row 7 and columns A to D:
=COUNT(E7:W7)
=INDEX($E7:$W7,0,$A7)
=MATCH($B7,$E7:$W7,0)
=SUM(INDEX($E7:$W7,0,$C7+1):W7)
If you need the position (or corresponding column header) of the last value that has changed, you can use Aggregate:
=AGGREGATE(14,6,D$1:U$1/((D2:U2<>"")*(C2:T2<>D2:U2)),1)
or if you have Excel 365, you can use Filter:
=MAX(FILTER(D$1:U$1,(D2:U2<>"")*(D2:U2<>C2:T2)))
Then you can use Index to find the value as before:
=INDEX(C2:T2,A2)
or use #Ron Rosenfield's formula.
Try:
=LOOKUP(2,1/((B4:Z4<>C4:AA4)*NOT(ISBLANK(C4:AA4))),C4:AA4)
This formula should return the last change, if I've understood the logic of what you are doing.
If not giving expected results, post back with an example of the failed row and what you expect.
Note that two horizontal references are used, with one being offset from the other by one column.

Which method i need to use?

I have the data table:
And i have the choose table:
I need some code, that can sum value by (for example :
if cells in choose table is not empty, then sum values from rows, where direction = 'East' and city = 'NY' and month = 10. (return 1)
If cells direction and month is empty, then sum values from rows,where city = 'NY' . return (4).
And etc...
If cells in choose table is empty, then sum values without limitation. (return 15).
This can be done with a SUMIFS formula. There is no need for VBA.
I'm going to assume the 'Choose' table is on another sheet in your real world, but the formula works if it's on the same sheet - I just wouldn't do it that way due to potential circular references if columns overlap.
Formula:
=SUMIFS(D:D,A:A,IF(B10="","*",B10),B:B,IF(B11="","*",B11),C:C,IF(B12="",">0",B12))
Basically, it replaces empty entries with a wildcard (where it's text) and with ">0" where the column is numerical. Tweak as you see fit.

How to add groups based on conditions in Excel?

I have a large set of data where I need to calculate the sum of groups for specific columns in a table. Here is an example of the table:
I need to sum up column H for each date group (column A) such that it will keep display this sum on the last row of the group. In other words, on the first group that we can visibly see here for 3/21/13, we would sum up 38 + 2 + 21 and display 61 to the right of cell H4930. This would be repeated throughout the data so as to display the sum of each group's H column entries at the lowest item in the group as aforenoted.
I am assuming that some VBA will be required here, but I am not sure how to attack this. How would this be done?
Yes as suggested by Idevelop ..you can get this done using pivot table
Select all the data -> goto Insert menu ->Pivot table > say ok
in Row field >Place A column title
in values field >place H column title
that's it
Let me know if you need more details.
Image :
I added 2 working columns before your Sum column.
Add: =NOT(ISNA(MATCH(C2,$Q$2:$Q$3,0))) to column N, where the Q2:Q3 are the numbers you wanted to check. Can be hidden.
Add: =IF(N2,COUNTIFS(A3:$A$7416,A2,N3:$N$7416,TRUE)=0,"") to column O. Can be hidden.
Add: =IF(AND(N2,O2),SUMIFS(H2:$H$2,A2:$A$2,A2,N2:$N$2,TRUE),"") to column P. This is your sum.
If you don't actually need to display all the data like this then a pivot table would be a lot clearer. You can filter based on numbers and so on easily.
edit: edited to check for specific codes in column C, per comment.
edit2: completely changed per comment. Requiring it to be inline with the last highlighted row is more complex.

Resources