Automatically calculate (or delete) rows in Excel when first column is changing - excel

I have a big table, where first columns X is "input column" and range it's changing.
Y - There are more formulas and functions (Vlookup) and 1st column X is a lookup value, and then other columns are calculated from other sheets.
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | X | Y | Y | Y | Y
4 | X | Y | Y | Y | Y
I am inserting (and deleting) more X values (actual data) and then I use "double click" for all other Y columns to be calculated, BUT it's not good because the X range is not the same. I tried to convert it to table "Ctrl-T", but it's not working very good for me. Maybe I don't use it properly.
Problem:
If I paste a new X column, I need other Y columns to be automatically calculated OR if I delete few X rows, other Y should be also deleted. Now I get something like this:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | | N/A | N/A | N/A | N/A
4 | | N/A | N/A | N/A | N/A
or:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | X | | | |
What I need:
If I remove X value I need automatically disappear Y values:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
If I add X value I need automatically calculate Y values:
| A | B | C | D | E
1 | X | Y | Y | Y | Y
2 | X | Y | Y | Y | Y
3 | X | Y | Y | Y | Y
Hope it's clear, thank you!

For Y Columns, you can add "IF" FORMULA
=if(A1>0,*Y COLUMN FORMULA*,"")

try changing formula to
=iferror(*Y formula,"")
or if it's still slow and if you are changing only X Columns
you can use below code
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column = 1 And Target.Count = 1 Then 'CHECK IF THERE IS ANY CHANGE ON X COLUMN
If Target.Value = Empty Then 'CHECK IF X COLUMN HAS BEEN DELETED
Rows(Target.Row).Delete 'IF X COLUMN IS DELETED, DELETS WHOLE ROW
Else
Cells(Target.Row - 1, 2).Resize(1, 4).Copy Cells(Target.Row, 2).Resize(1, 4) 'IF X COLUMN IS ENTERED OR MODIFIED COPIES ABOVE Y COLUMN FORMULAS
End If
End If
End Sub

Related

Count categorical values in DataFrame

I have DataFrame only with Categorical Values
Col1 | Col2| ... | ColM
Row
1 X | Y | ... | X
2 Z | X | ... | Y
3 Y | Z | ... | X
.
.
.
N X | Z | ... | Z
I would like to count how many times each category appeared in database
So example result:
X - 100 times
Y - 30 times
Z = 210 times
Thank You for help
The most performant option is to use np.unique with the return_counts flag set:
u, c = np.unique(df, return_counts=True)
pd.Series(c, index=u)
There's also stack and value_counts, which is much slower, but simple and intuitive:
df.stack().value_counts()

Looking up values in third column by two criteria

I have a list similar to this one:
NO | Cat1 | Cat2 | | Crit1 | Crit2 |
---|------|------| | A | O |
5 | A | O |
3 | K | Y |
6 | K | Y |
7 | F | K |
8 | A | O |
9 | J | H |
10 | K | Y |
5 | F | T |
50 | A | O |
8 | L | E |
1 | R | D |
Based on two criteria I want a dynamic list which changes everytime the content are changed or the criteria are changed.
If criteria is A O then the list should be as below,
|List|
|----|
| 5 |
| 8 |
| 50 |
If any other criteria is selected the list will be longer or shorter and if nothing is present it is shown as a blank cell.
I have tried some MATCH and INDEX formulas but I cannot make it work correctly.
=IFERROR(INDEX(LookUpList;MATCH(0;COUNTIF(NewList;LookUpList)+IF(Cat1<>Crit1;1;0)+IF(Cat2<>Crit2;1;0);0));"")
Sorted ascending:
=IFERROR(AGGREGATE(15,7,A$2:A$12/((B$2:B$12=G$1)*(C$2:C$12=G$2)),ROW(1:1)), "")
Ordered by row:
=IFERROR(INDEX(A:A, AGGREGATE(15, 7, ROW(A:A)/((B$1:B$12=G$1)*(C$1:C$12=G$2)), ROW(1:1))), "")
Pick one formula then fill down for subsequent matches.

LibreOffice/Excel Table Calculation Formula

I have three Columns in one sheet. Col1 Have Combination Of Col2 Values, I need to replace Col1 Value as equal Of COl2 = col3 Value.
Is there Any Formula to do this in LibreOffice Calculation.
Actual Table:
Col1 | col2 | Col3
A | A | X
C | B | Y
A | C | Z
B | |
A | |
B | |
C | |
A | |
C |
B |
Expected Output:
Col1 | col2 | Col3
X | A | X
Z | B | Y
X | C | Z
Y | |
X | |
Y | |
Z | |
X | |
Z |
Y |
Thanks In Advance, I am struggling For long days in this.
Basically it's a work around. You would like to change A->X, B->Y and C->Z in col1. Create a col4 with the formula
=CHAR(CODE(A1)+23)
This offsets the A by 23 characters that will be X and therefore, B and Cs with Y and Z.

Search a string in multiple columns

I am using the following formula:
=IF(ISERROR(LOOKUP(2^15;SEARCH(MID(A1;1;9);$D$1:$D$100)));"No";"Yes")
this is working perfectly!
Question: I want to search within columns $D$1:$E$100 and not only one column D. How can I modify this to search in two columns?
The easiest way is probably to AND the results of a search in each column. This translates to "if not found in D and not found in E then output No". The logic is as follows:
In column D | ISERROR(lookup in D) | In Column E | ISERROR(lookup in E) | result
N | Y | N | Y | No
N | Y | Y | N | Yes
Y | N | N | Y | Yes
Y | N | Y | N | Yes
=IF(AND(ISERROR(LOOKUP(2^15,SEARCH(MID(A1,1,9),$D$1:$D$100))),
ISERROR(LOOKUP(2^15,SEARCH(MID(A1,1,9),$E$1:$E$100)))),"No","Yes")

Insert new columns only when ID is the same in Excel

I have 2 worksheets with similar table structures which looks like this:
| ID | A | B | C |
+--------+-------+-------+-------+
| 1 | x | x | x |
| 4 | x | x | x |
| 12 | x | x | x |
| 3 | x | x | x |
| |
| ... (thousands of rows)
where x are values. Is it possible to create a new table (or worksheet) combining the two worksheets only where the ID from Worksheet1 is the same (similar to a SQL query) so that the resulting table will be like:
| ID | A | B | C | D | E | F |
+--------+-------+-------+-------+-------+-------+-------+
| 1 | x | x | x | x | x | x |
| 4 | x | x | x | x | x | x |
| 12 | x | x | x | x | x | x |
| 3 | x | x | x | x | x | x |
| |
| etc...
Note that the contents of Worksheet1 is added to and not subtracted from. Is VBA necessary or can it be done with a formula? Thank you.
You can use vlookup to solve this.
vlookup searches for id in sheet2 and returns corresponding value in your specified column number of the selected table.

Resources