Comparing multiple columns in multiple worksheets and color if found - if-statement

I am trying to compare 2 worksheets and 2 columns and then color the matches red.
For example,
Worksheet1
123 1.5
345 2.5
567 3.5
789 4.5
Worksheet2
124 1.5
367 2.5
567 3.5
891 4.5
I want to compare these worksheets and if column A in WK1 matches column A in WK2 and column B in WK1 matches column B in worksheet 2 color row red.

Don't use an IF statement to color the cel. Use conditional formatting.
As far as getting the values from another file, use the following sytax:
='[fileName.xlsx]sheetName'!C22

Related

how to compare values between 2 columns, if match , output corresponding column

I Have an excel workbook that has 2 tab tab reference & Sheet 3
i want to compare Column W from sheet 3 with Column D from tab reference
If they match, it will output corresponding Colomn E value to Column AP.
Otherwise just leave blank
tab reference
Colomn D Colomn E
001 321
002 554
003 789
Sheet 3
Column W Column AP
012
002
048
001
Desired Result
Sheet 3
Column W Column AP
012
002 554
048
001 321
Any idea? Thankyou.
Use VLOOKUP and enter the following formula into the AP column, row 2 (assuming the first row is row 2):
=IFERROR(VLOOKUP(W2,'tab reference'!$D$2:$E$3,2,FALSE),"")
The range 'tab reference'!$D$2:$E$3 refers to the lookup data you showed us. This assumes you only have three rows to lookup, but you may change this formula if you have more than this.

PowerBI - Get the Index of the First Occurance of a value in the column

I am trying to return the Index of a first occurrence of a value in a column.
I would want to use the Calculated Column functionality in PowerBI.
For Example,
Input Output
ASD 1
ASD 1
ASD 1
GEF 4
GEF 4
HIJ 6
GEF 4
This can be done in excel using a simple formula like,
MATCH(A2,A:A,0)-1
For PowerBI to understand Index, I have created a column called as Index on the Query editor and made the data look like,
Index Input Output
1 ASD ?
2 ASD ?
3 ASD ?
4 GEF ?
5 GEF ?
6 HIJ ?
7 GEF ?
How to do this in PowerBI?
The way I did this was to find the minimal index the corresponds to the Input value in the table:
Output = MINX(
FILTER(TableName,
TableName[Input] = EARLIER(TableName[Input])),
TableName[Index])
This takes the minimal index over the table, where Input matches the value of Input in the original (earlier) row context.

Pandas regex split on characters and group

I've never got around to learning regex till now, but I'm trying to figure out how to use it in pandas with Series.str.match(expression) In order to split one column to make two new columns. (I know I can do this without regex)
examples of the column data are:
True Grit {'Rooster Cogburn'}
The King's Speech {'King George VI'}
Biutiful {'Uxbal'}
Where there can be any number of strings greater than 1 in each of the two groupings. How can I extract two groups to result in True Grit, Rooster Cogburn?
Given this dataframe
col
0 True Grit {Rooster Cogburn}
1 The King's Speech {King George VI}
2 Biutiful {Uxbal}
df = df.col.str.extract('(.*)\s*{(.*)}', expand = True)
will return
0 1
0 True Grit Rooster Cogburn
1 The King's Speech King George VI
2 Biutiful Uxbal

Excel 2007 Report Number of Occurrences in Second Column

B5:B53 Is a list of values I will be pasting into regularly.
In C5:C53 I would like to count the occurrences of the item.
SO:
Apple 1
Banana 1
Orange 1
Apple 2
Plum 1
Orange 2
Apple 3
I just can't seem to get the COUNTIF (think that's what should do it) to work.
Then when I go back in and paste another list into that B column range the C column will update.
You need to make the range dynamic. The first cell in the range is fixed while the second is relative:
=COUNTIF($A$1:A1,A1)
So as it is dragged/copied down the second part of the range will change thus always looking from the cell up.

'two' Regular expression between two regular expressions

I have a .asc file with around 80 000 lines and I want to extract some specific lines from the file.
I have tried to make it easier for me by putting to specific lines (one before and one after) the areas where I want to extract information/ lines (150 areas).
The 'start' regex (MSG\s*(\d{1,8})\sSHOWING\sSENTENCE) so I want to look for lines after this occur
the 'end' regex (MSG\s*(\d{1,8})\sSENTENCE\sGONE) so when this occur I won't have anything returned until the 'start' regex appear again.
There will be hundreds of lines between these two regex expressions, but I only want those matching these regex's
(EFIX\sR\s*(\d{1,8})\s*(\d{1,8})\s*(\d{1,3})\s*(\d{1,3}).\d\s*(\d{1,3}).\d\s*(\d{1,4}) or (ESACC\sR\s*(\d{1,8})\s*(\d{1,8})\s*(\d{1,3})\s*(\d{1,3}).\d\s*(\d{1,3}).\d\s*(\d{1,4}).
How would I go about this in Python?
It could be easily done with the following steps:
Capture contents in between 'start' regex and 'end' regex patterns;
match:
(EFIX\sR\s*(\d{1,8})\s*(\d{1,8})\s*(\d{1,3})\s*(\d{1,3})\.\d\s*(\d{1,3})\.\d\s*(\d{1,4}) or (ESACC\sR\s*(\d{1,8})\s*(\d{1,8})\s*(\d{1,3})\s*(\d{1,3})\.\d\s*(\d{1,3})\.\d\s*(\d{1,4})\.
So the sample code could be:
import re
P1 = 'MSG\s*\d{1,8}\sSHOWING\sSENTENCE([\s\S]+?)MSG\s*\d{1,8}\sSENTENCE\sGONE'
P2 = 'EFIX\sR\s*\d{1,8}\s*\d{1,8}\s*\d{1,3}\s*\d{1,3}\.\d\s*\d{1,3}\.\d\s*\d{1,4}|ESACC\sR\s*\d{1,8}\s*\d{1,8}\s*\d{1,3}\s*\d{1,3}\.\d\s*\d{1,3}\.\d\s*\d{1,4}\.'
sample = """
ESACC R 000000 7777 333.3 222 1111.
MSG 2355688 SHOWING SENTENCE
some text in between
EFIX R 5656 7878 123 456.8 122.9 5656
some text 1 here
some text 2 here
ESACC R 1075390 1075414 25 144.3 526.2 54.3 547.2 1.86 162
some text 3 here
some text 4 here
EFIX R 1212 505050 222 000.2 129.9 1010
some text 1 here
some text 2 here
ESACC R 1212 505050 222 000.2 129.9 1010.
some text 3 here
some text 4 here
MSG 2355688 SENTENCE GONE
EFIX R 5555555 8888888 9 666.6 999.8 0000
"""
in_between = re.findall(P1, sample)
for txt in in_between:
print re.findall(P2, txt)
Output:
['EFIX R 5656 7878 123 456.8 122.9 5656', 'ESACC R 1075390\t1075414\t25\t144.3\t526.2\t54.', 'EFIX R 1212 505050 222 000.2 129.9 1010', 'ESACC R 1212 505050 222 000.2 129.9 1010.']