a cell containing the same value of another cell in column - excel-2007

P12100600006 P12100100000 P12100600000 121006
P12100600006 P12100100000 P12100600000 121006
M12200100012 P12100400000 P12110100001 121101
P12200700000 P12100400000 P12100600000 121006
M12200100012 P12100400000 P12110200016 121102
M12200100012 P12100500000 P12100100000 121001
M12200100012 P12100600000 P12100500000 121005
P12200700000 P12200100000 P12200700000 122007
P12200700000 P12200100000 P12200700000 122007
P12200700000 P12200100000 P12200700000 122007
P12200700000 P12200100000 P12200700000 122007
P12200700000 P12200100000 P12200700000 122007
P12200700000 P12200100000 P12200700000 122007
P12200700000 P12200100000 P12200700000 122007
M12200100012 P12200100000 P12200600000 122006
P12200100001 P12200200000 P12200400004 122004
R12200100000 P12200400000 P12205200000 122052
R12200100000 P12200400000 P12205200000 122052
R12200100000 P12200400000 P12205200000 122052
P12200500000 P12200400000 P12200700000 122007
P12200100000 P12200700000 P12200100000 122001
In the above given data I want if A1 contains the value in D1 respectively like A2 contains D2 and so on. In excel for example in last row column A is P12200100000 having the value of D columns whose value is 122001
otherwise find if first 7 element of column A and Column C are same

=IFERROR(FIND(D1,A1),LEFT(A1,7)=LEFT(C1,7))
copied down should give a numeric result if in the same row (starting at 1) the value in ColumnA contains the value in ColumnD. Otherwise, if the first seven characters of ColumnA are the same as the first seven characters of ColumnC of the same row the result should be TRUE. If neither of these the result should be FALSE.
But as with others, I am not certain whether this is your requirement, only that is how I think it can be interpreted.

Related

R tableGrob cell colors with condition on multiple columns

Is there a way to put colors on all the cells of a tableGrob that are not 0 ?
I have this table with a lot of lines
[][1]
[1]: https://i.stack.imgur.com/w7RCJ.png
I am using tableGrob and then grid.arrange to put 2 tables on the same page with some text
tab1<-tableGrob(tab_glob,rows=NULL,theme = ttheme_default(10),widths=unit(rep(1/ncol(tab_glob), ncol(tab_glob)), "null"), heights=unit(rep(0.95/nrow(tab_glob), nrow(tab_glob)),"npc"))
tab2<-tableGrob(Notes_tous,rows=NULL,theme = ttheme_default(11))
footnote<- textGrob("Moyenne référence = résultats techniciens référents")
padding<-unit(0.5,"line")
tab3<-gtable_add_rows(tab2,
heights = grobHeight(footnote)+ padding,pos=0)
tab3 <- gtable_add_grob(tab3,list(footnote),
t=1, l=1,
r=ncol(tab2))
pdf(paste("Table_",i,".pdf",sep = ""),width=10,height=15) #save in pdf
Point_tab<-grid.arrange(tab1,tab3,ncol=1,nrow=2, top=textGrob("\n \n \nNombre de pointages par note",gp=gpar(fontsize=14,font=3)))
dev.off()
In the first table, showing all the values, I am looking for a way to highlight the values that are not 0 in all the columns. All the answers I have found on the internet are for particular cells or a particular value... Do you have any idea to help me update my code ?
Kind regards,

SQLAlchemy maria Db column encoding problem

I am pulling a table from a maradb database using SQL Alchemy like so:
engine=db.create_engine('mariadb+mariadbconnector://username:password#127.0.0.1:3306/dbname?charset=utf8mb4')
then create the connection
connection = engine.connect()
I then add a select statement and put the table in a pandas data frame
from sqlalchemy.sql import text
objects = text(''' SELECT * FROM objects 0
INNER JOIN area a ON a.id =o.area_id LIMIT 10;''')
raw = pd.read_sql(objects,connection)
So far so good, but when I access the data frame the uuid column is in the bellow format
0 b'\x05\xd5\x0b\x80\xf4\x05O\xd3\x9e\x17\x88\xb5p\xca\x8d6'
1 b'Q\xddJ\xd6y\xdeOG\xad\xdc\xbc#\xb5,\xfe\x08'
2 b'z\xde\xb7\xb8\x160O\xc9\x80\x0b\x96\xbaR\x04k\r'
3 b'\xeb\x7f\xb9~\xa8\x0eO\x9f\x87\xea`#\x16)QD'
4 b'\x051\xc1\x81\xbf\xe2O!\xa3AT\xa1\xf7X\x92\xbc'
5 b'\x1c\x00x\x99\xbbQO\xc9\xbdZ\xccb(K5b'
6 b'DFg\xa7_\xfeO\xe3\x95\x95-u\xd7\xed\x90\xd8'
7 b'\x91\xba\xe0\xe2\x1c\xe7OS\xbbW\x0b\xcd\t\x85V\xf0'
8 b'`\xdb\xd7\xba~\xdeO\xb2\xa5\xcd)\x00\xa5&\xa0,'
9 b'%\x06\xf5<_\xa7O\x08\x9c\x90\n|t\xc8\x95\xdc'
Going back to the database and executing the same query I get the bellow result in the uuid column
1 Õ ô OÓ µpÊ 6
2 QÝJÖyÞOG­Ü¼#µ,þ
3 zÞ·¸ 0OÉ ºR k
4 ë ¹~¨ O ê`# )QD
5 1Á ¿âO!£AT¡÷X ¼
6 x »QOɽZÌb(K5b
7 DFg§_þOã -u×í Ø
8 ºàâ çOS»W Í Vð
9 `Û׺~ÞO²¥Í) ¥& ,
10 % õ<_§O |tÈ Ü
I understand I am having an encoding problem and I tried decoding-encoding like bellow
raw.uuid.str.encode('utf-8')
but I am stuck. Any pointers are much appreciated. On how I can fix this problem on the source or at least at the data frame lvl.
MariaDB Connector/Python sets utf8mb4 by default and doesn't accept another character set.
Since the result is a binary object, the uuid was stored in a blob (binary) column. Instead of trying to encode it, you need to convert it to a string:
>>>import uuid
>>>uuid.UUID(bytes=b'\x05\xd5\x0b\x80\xf4\x05O\xd3\x9e\x17\x88\xb5p\xca\x8d6')
UUID('05d50b80-f405-4fd3-9e17-88b570ca8d36')

Query function to pull data based on multiple values within one cell

I would like to ask how to use Query function where one of the cell contains multiple comma separated values
For example:-
To pull col2 values when Col 1 is B, it would be straightforward.
Col 1
Col 2
A
1
B
2
C
3
D
4
=QUERY(A1:B3,"select B where A = '"&D3&"' ",0)
D3 cell value is B
Similar to how we have IN clause in SQL, I would like to pull data from col 2 when col1 values are B,C,D.
Would it be possible to concatenate the results in one row as well?
Try this one:
=join(", ", QUERY(A1:B4,"select B where "&CONCATENATE("A = '", join("' or A = '", SPLIT(D4, ",")), "'"),0))
Where D4 = B,C,D
Sample Output:
Note:
The values on column B below are the value of the formula:
CONCATENATE("A = '", join("' or A = '", SPLIT(D4, ",")), "'"),0))
Since there was no in statement in sheets query (not that I have encountered), what I did was split those said values in column D and have them format like the multiple or statements which are equal to a single in statement. This is a workaround and should do what you wish to achieve.

Issues with Empty String Values in SQL

I'm using an update statement to replace any Null or empty string values with "No Cost Center". The data that I have imported into the table has numerous blank/empty string values and when I run the code below, it affects 0 rows:
Update [dbo].[Import_tbl_Inventory] Set [dbo].[Import_tbl_Inventory].[User Defined Label 4] = 'No Cost Center'
Where [dbo].[Import_tbl_Inventory].[User Defined Label 4] is Null or [dbo].[Import_tbl_Inventory].[User Defined Label 4] = ''
Is there something other than NULL and Empty String values that I need to be checking for?
EDIT:
Upon further review, I decided to right click the table and select Edit top Rows. Here I discovered that each row in the User Defined Label 4 column actually contains spaces. I was able to delete the spaces out of the first 2 rows manually, but any rows after that give me a message saying Data in row was not committed. The row values updated or deleted either do not make to the row unique or they alter multiple rows
I'm only altering one row at a time, and there is no reason this should have anything to do with making the row unique. Now sure what's going on here.
A "blank" string could be a nonempty string of whitespace characters, which might not be easy to distinguish visually from an empty string. Depending on how you view it, maybe not from NULL, either. To include rows having such values in your update, you can trim them before comparing with the empty string:
Update [dbo].[Import_tbl_Inventory]
Set [dbo].[Import_tbl_Inventory].[User Defined Label 4] = 'No Cost Center'
Where [dbo].[Import_tbl_Inventory].[User Defined Label 4] is Null
or RTRIM([dbo].[Import_tbl_Inventory].[User Defined Label 4]) = ''
You could use LTRIM() instead of you prefer, but you don't need both because if the string contains only whitespace then passing it to either LTRIM() or RTRIM() will yield an empty string.
You need to check for unprintable characters like tab and line feed
you can try LTRIM and RTRIM in your Column and Check the LEN
Update [dbo].[Import_tbl_Inventory] Set
[dbo].[Import_tbl_Inventory].[User Defined Label 4] = 'No Cost Center'
Where
LEN(RTRIM(LTRIM(ISNULL([dbo].[Import_tbl_Inventory].[User Defined Label 4],''))))=0
You can use REPLACE
Update [dbo].[Import_tbl_Inventory] Set
[dbo].[Import_tbl_Inventory].[User Defined Label 4] = 'No Cost Center'
Where
LEN(REPLACE(ISNULL( [dbo].[Import_tbl_Inventory].[User Defined Label 4],''),' ',''))=0
A little cleaner without or
Update [dbo].[Import_tbl_Inventory] Set [dbo].[Import_tbl_Inventory].[User Defined Label 4] = 'No Cost Center'
Where len(isNull([dbo].[Import_tbl_Inventory].[User Defined Label 4], '')) = 0

How do I match 2 columns data and when a match is found copy a 3rd column of data to a 4th blank column

Example:
Column A Column B Column C Column D
90516-9240 107461 107461
90516-9574 124174 107461
90516-9665 143064 124174
90516-9268 148725 124174
90516-9267 161747 128986
90516-9586 171964 133339
where if any number in column B matches any number in column D then the number from column A will fill to column C
so it would look like this:
Column A Column B Column C Column D
90516-9240 107461 90516-9240 107461
90516-9574 124174 90516-9240 107461
90516-9665 143064 90516-9574 124174
90516-9268 148725 90516-9574 124174
90516-9267 161747 128986
90516-9586 171964 133339
What is the simplest formula I can use to do this.
This can be done with a lookup using Index/Match. Assuming row 1 has labels, start in C2 with
=index(A:A,match(D2,B:B,0))
If you swap columns A and B, you can use a Vlookup():
=vlookup(D2,$A$1:$B$1000,2,false)
Copy down.