New Column based on formula (Excel or Pandas) - excel

[1]: https://i.stack.imgur.com/ESmJ4.png
I want to create new column based on formula on values of other columns. Col-C is the most important and Col-A is the least. Need a formula in excel or pandas to get result as in image. Any help is much appreciated.

First forward fill all mising values and then select last column by position by iloc:
df = pd.read_excel('file.xlsx')
df['Result']= df[['ColA','ColB','Colc']].ffill(axis=1).iloc[:, -1]

This formula checks whether the cell in the column is empty one by one, and returns the value of the first non-blank cell from C to A. If it finds no data, the cell remains empty.
=IF(ISBLANK(C1);IF(ISBLANK(B1);IF(ISBLANK(A1);"";A1);B1);C1)

Maybe it's not too elegant, but it works - you fill null values with each column's values, one by one, starting with the most important.
import pandas as pd
df = pd.read_excel('....xlsx')
df['Result']=df['Result'].fillna(df['ColC'])
df['Result']=df['Result'].fillna(df['ColB'])
df['Result']=df['Result'].fillna(df['ColA'])

Related

find cell value after matching for row number and column number

I want to find which user is "P" given a date in data below.
I've tried retrieving the row number of the given date using "=MATCH(A5,$A$4:$A$5,0)"
and also the column number of "P", using "=MATCH("P",B5:G5,0)"
I'm unsure how to bring them together to get the desired output.
Thanks for any help.
Nested INDEX/MATCH
=IFNA(INDEX($B$1:$G$1,1,MATCH($J2,INDEX($B$2:$G$3,MATCH($I2,$A$2:$A$3,0),0),0)),"")
Insert a new column H where H4 has a formula of =INDEX(B$3:G$3,MATCH("P",B4:G4,0).
Then your second table's second column formula can be =INDEX(H$4:H$5, MATCH(yourDateCellHere, A$4:A$5,0)) because a lot of the heavy lifting is already done in the first table.
Then, if you wish, hide your new column H.

Xlookup range formula

I got an issue with Xlookup formula for the lookup array & return array. As the 1st one I need to manually select the range for lookup and return array, I try to use Xlookup with multiple criteria to match with the keyword instead of only matching one criteria. However, the result was appear to be different. Please help how to adjust the formula to remove the manual selecting range. Thank you.
G column is text
AE column is number
J column is text
Z column is number
W column is date
=XLOOKUP(AE3,工作表2!$Z$2:$Z$6,工作表2!$W$2:$W$6,,1)
=XLOOKUP($G3&$AE3,工作表2!$J:$J&工作表2!$Z:$Z,工作表2!$W:$W,,1)
Your sheet names showing in Chinese may be confusing some people.
I'm not aware of any syntax in Excel that allows you to concatenate columns as part of an array definition. It would be great if we could do this. The only way I know to do this is with another column and then use that for your array. You could add $J2&$Z2 to another column and then use that. If you added that to column H your xlookup() would be:
=xlookup($G3&$AE3, $H2:$H6, $W2:$W6,,1)
Here's how it looks. I showed the xlookup() functions in F9 and F10 (right aligned) and the results in G9 and G10.

Excel duplicate rows to CSV cell formula

I have an Excel spreadsheet such as this: (See Columns A through D of "Formula Output Column E" image - had to remove original 1st image due to not enough reputation points)
And would like to make a formula to consolidate it so that when the first three columns are duplicates, the last column gets combined into one CSV cell such as this: Excel Finish
I'm thinking it can get there with the right combination of Index and Match functions, but I haven't gotten it to work yet.... any help would be much appreciated! Thanks.
I currently have the following formula:
=IF(AND(A2=A1,C2=C1),"",D2&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+1,4)&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+2,4)&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+3,4)&",
"&INDEX(A2:D17,MATCH(A2,A2:A17,0)+5,4))
Which yields this ouput in Colum E: Formula Output Column E
As you can see, it either includes too many rows (Row 2 and 6 output) or too few (Row 8 output). Hope this helps, thanks.
If you have two extra columns and type
=IF(AND(A2=A3,C2=C3),D2&","&E3,D2)
in cell E2 and
=IF(AND(A2=A1,C2=C1),"",E2)
in cell F2 like in the following example
Then you will get the output for column CSV Output correct but in row F instead of row E, as below when you fill the formula to the bottom.
Here is the array formula (means you have to click Ctrl + Shift + Enter altogether) you can use in your CSV Output column:
{=IF(OR(ROW(E1)=1,MAX(--($A$1:A1=A2)*--($B$1:B1=B2)*--($C$1:C1=C2)*ROW($A$1:A1))=0),D2,INDEX($E$1:E1,MAX(--($A$1:A1=A2)*--($B$1:B1=B2)*--($C$1:C1=C2)*ROW($A$1:A1)))&", "&D2)}
Here is the explanation but I also included a picture for your reference:
Column F: This is to find the last matched row and this is also an array formula:
{=MAX(--($A$1:A2=A3)*--($B$1:B2=B3)*--($C$1:C2=C3)*ROW($A$1:A2))}
The -- just easy to see when you evaluate formulas. You can remove them if you want.
Column G: This is to concatenate the prior outcome:
=IF(OR(ROW(G1)=1,F2=0),D2,INDEX($G$1:G1,F2)&", "&D2)
Hope this helps. Please let me know if you have any question.

Apply Countifs function to last non empty row in Excel

I have 4 columns in excel. Data for first three column is getting populated by using Macro. On 4th column, I have applied Excel function countifs. I have applied it till 100th row. So if data is more than 100 row, function does not get apply to remaining rows. I want that, this formula should apply automatically to all those rows which contain non empty data may be those are less than 100 or more than 100. Please help.
Please try:
=SUM((A:A=B:B)*(A:A<>""))
entered with Ctrl+Shift+Enter.
Apply something like this to every cell in your 4th column
=IF(expression, when-true, else)
In expression you want to check if A and B are valid and probably your else will be an empty value

Search for numeric values within cells containing both alpha and numeric values-VBA Excel

I have a spreadsheet with one column, Column "M," that has rows containing alpha numeric values like the following: 103.14 Jose Dolorez Chavez. I am not sure if there is code out there that can loop through each row of cells, cut the numerical values and paste them into an adjacent column. So At the end, I would have:
one column: 103.14 another column: Jose Dolores Chavez
Could someone help me. I'm not sure where to start. The code would need to loop through all 500 rows in column "M," find/cut the values, and paste them into column "N."
Any advice would be greatly appreciated and thank you in advance.
No, the pattern remains the same throughout: Number, followed by Employee name. – Dora 13 mins ago
You do not need VBA for this. You can easily achieve this via Text To Columns.
Highlight Column M and click on Data | Text To Columns | Delimited
Select space as delimiter and click on finish and you are done. See snapshot here
Uploading the screenshot in wikisend.com as it seems like imgur is down today.
Here's a VBA function you can use. It uses the Val function, which returns the numeric part at the beginning of a string. Just put it in a regular code module in your workbook:
Function GetNumAtBeginOfString(StringWithNum)
GetNumAtBeginOfString = Val(StringWithNum)
End Function
Then in column O put this formula (assumning your data starts in row 2):
=GetNumAtBeginOfString(M2)
And if column N put this formula:
=TRIM(SUBSTITUTE(M2,O2,""))
... and copy down.
This leaves you with the original string and two new columns. If you want you can copy and paste over the original.
EDIT: you can use this Excel formula in column O instead of the VBA function:
=MAX(IF(ISNUMBER(LEFT(M2,ROW($A$1:$A$100))*1),(LEFT(M2,ROW($A$1:$A$100))*1),0))
It's an array formula and must be entered with Ctrl-Shft-Enter

Resources