create a calculated column in table to equal another column in a different table based of a where statement - calculated-columns

Learning SQL and need help
I have two tables, list1 and list2.
list1
proj | revision | drawing
123 | A | 1200
123 | 00 | 1300
list2
proj | revision | dwg
| | 1200
| | 1300
I want to create calculated columns in table list2 for proj and revision columns to equal table list1 when column dwg in table list2 = column drawing in table list1.
I have done calculated columns with case statements when it was all in one table but dealing with two tables has me confused.
Thanks for any help.

Related

PowerPivot Count Occurrences of Partial String in Table1 Column Based upon Table 2 Column

I am learning PowerPivot by reading posts but I haven't found an answer for this issue.
I have Table 1 (Products) with 2 columns (number and description) and about 100 rows.
Products
| Item | Description |
| 001 | Blue Widget |
| 002 | Green Widget|
| 003 | Red Widget|
I have a second table, Invoice. It has multiple columns, but for my purposes the important column is ItemsPurchased. That column will have a string of product items. For example
|InvoiceNum|ItemsPurchased|
| 3843 | 001, 003 |
| 3953 | 002 |
| 4002. | 003, 002 |
There are about 6000 rows which will keep growing. They are not not related since the ItemsPurchased could have multiple Item Numbers.
I am trying to get a calculated field in the Products Table to look like this:
| Item | Description | Count
| 001 | Blue Widget | 1 |
| 002 | Green Widget | 2 |
| 003 | Red Widget | 2 |
I made a measure calculating this:
001:=CALCULATE(COUNTROWS(Invoice),SEARCH("001",Invoice[ItemsPurchased],,0))
But the problem with this is I would need to write 100 measures and I would not be able to filter them to a Top 10 list in the pivot table.
I found on another website the following formula:
=CALCULATE(COUNTA(Invoice[ItemsPurchased]),FILTER(Invoice,Invoice[ItemsPurchased]]=Products[Item]))
but it doesn't search for a partial phrase and it doesn't list the Products[Item] column in the auto populate of the formula bar. I have tried different ways of combining the formula in the measure with the formula above, but I get various errors.
Is this even something that can be done in PowerPivot? I don't understand how to make a calculated column that will take the item number from each row in that column and count the number of occurrences in the Invoice Table's ItemsPurchased column.
Any tips on what I am doing wrong would be appreciated.
Thanks!

Finding Duplicates and Creating a column which points out the duplicates in pandas

| Col1 | Col2 | Col3 |
|------|------|------|
| m | n | o |
| m | q | e |
| a | b | r |
Let's say I have a pandas DataFrame as shown above. Notice the col1 values are same for the 0th and 1st row. Is there way to find all the duplicate entries on the dataframe based on Col1 only.
Additionally i wold also like to add another column say is_duplicate which would say True for all the duplicate instances of my DataFrame and False otherwise.
Note: I want to find the duplicates based only on basis of the value in Col1 the other columuns can be or might not be duplicates, They should'nt be taken into consideration.
.duplicated() has exactly that functionality:
df['is_duplicate'] = df.duplicated('Col1')
I found it :
df["is_duplicate"] = df.Col1.duplicated(keep=False)

Excel formua like SUMIFs with criteria in different tables

I don't know if I am missing something obvious or what, but I cannot wrap my brain around what I need from this. I have a table with products available for sale and various criteria. I have a second table with a smaller list of stores and a second column of whether I should include them in my results set. In this example, I would never include store 789, but I might include 123 and/or 456, depending on whether an "x" was placed in that second column.
So, for my results, I would break them out by Product and color with a simple SUMIFS statement. However, I really want to be able to filter the sites out if they are "x" on that second tab. Any thoughts on how I could easily do that? I did insert a column on my raw data sheet and just added an if statement, then I used that as a 4th criteria in my SUMIFS, but I was looking for a more elegant solution.
I can get either matching stores or the rest of the filters, but I cannot figure how to make both work together in the same statement or how to include them if they are "x"-ed.
This will get me the filtered stores
=SUMPRODUCT(SUMIF('Tab1'!A:A,'Tab2'!A:A,'Tab1'!D:D))
Either of these will get me the filtered products:
=SUMIFS('Tab1'!D:D, 'Tab1'!B:B, A2, 'Tab1'!C:C, B2)
=SUMPRODUCT(--('Tab1'!B:B=A2), --('Tab1'!C:C=B2), 'Tab1'!D:D)
Tab1
Store | Product | Color | Sales
--------------------------------
123 | A | Red | 1
123 | A | Blue | 2
123 | B | Red | 4
456 | A | Blue | 8
456 | B | Red | 16
789 | A | Red | 32
789 | B | Red | 64
Tab2
Store | Include
---------------
123 |
456 | x
Results:
Product | Color | Sales
------------------------
A | Red | 0
A | Blue | 8
B | Red | 16
Why not use VLookUp's to add the column from Tab2 to Tab1?
For example, new Column E, to the right of Sales:
=VLookUp(A1, "Tab2", 2, False)
...and fill-down?
You could base SumIf criteria on multiple tables but personally I'd just keep the data together (dynamically) just to make it easier and neater.
Build a pivot table and use slicers to include or exclude specific data. Then you don't need a helper table and you don't need formulas, either. Just a few clicks.

Pattern finding algorithms in NodeJS

I am working on a server that will update a list each day. The list will look like the following example.
+---+------------+-------------+-------------+-------------+
| | A | B | C | D |
+---+------------+-------------+-------------+-------------+
| 1 | Name1 | 1 | 2 | true |
| 2 | Name2 | 2 | 3 | true |
| 3 | Name3 | 1 | 1 | false |
+---+------------+-------------+-------------+-------------+
In this example I only used 2 table (except for the name) but in the real list there are 15 columns, with each containing other numbers (some columns can also have the same value).
I also have a last column that is filled with value true or false. This column will be filled on the next day that i receive the other values.
What I want to program is a algorithm that will be able to search for a pattern(s) that are most common for all the row's with he value true.
I want to program this in NodeJS but have no idea how I am able to do this, any idea's?
considering the algorithm is derived from previous stored values of various columns which correspond to last column being true.
If we consider linear relationship between various columns like
y=a1*c1+a2*c2...+a14*c14
where c1 is column 1 and a1 is coefficient.Then for example we "might" get some relation like.
y>0.5 then true
y<0.5 then false
but remarks are
this will only hold true if there exists a linear relation between the columns.
This will be fuzzy clustering i.e. there might be outliers when you calculate true or false with your above equation.
Some non linear relation ship might exist between the column values which may not be covered in above relationship.

Excel search value from whatever row and if found on another row replace that row with the value in the first row

What I am Trying to do is
lets say I have a excel sheet with
rows
ProductNo | Product | Sku | Price | Image | Thumb
25 | Shirt Blue | 4251 | $10 | shirt.jpg | shirtthumb.jpg
2 | Shirt Green | 4581 | $17 | green.jpg | greenthumb.jpg
8 | Shirt Black | 4561 | $15 | black.jpg | blackthumb.jpg
and just in different rows or on another excel sheet
ProductNo | Product | Sku | Price | Image | Thumb
25 | Shirt Blue | 4251 | $52 | |
2 | Shirt Green | 4581 | $42 | |
8 | Shirt Black | 4561 | $65 | |
How can i change the first table to update if the the second table or sheet columns data is different on specified columns and if the cells are empty forget about them ignore them and just replace the values from the second table onto the first
Final would be
ProductNo | Product | Sku | Price | Image | Thumb
25 | Shirt Blue | 4251 | $52 | shirt.jpg | shirtthumb.jpg
2 | Shirt Green | 4581 | $42 | green.jpg | greenthumb.jpg
8 | Shirt Black | 4561 | $65 | black.jpg | blackthumb.jpg
I have tried a couple of excel functions but they do not work since i have so many products to be doing cell additions
I tried doing in Vl but got confused and macro i dont even know what it is
Im open to whatever visual, functions just as long as i can perform the task
if anybody know hos let me know
Thank You
in stead of having the fixed values I propose you use a permanent formula in the specified columns.
Now to do this I would use a VLOOKUP() function. I am assuming that your ProductNo is the element that never changes therefore all the other columns will get a VLOOKUP() function.
Now if I understand correctly you MIGHT have an update in the 2nd table for the 1st table, but any empty cells in the 2nd table should be ignored.
I am also assuming you wish to see when an element will change because of the update therefore I propose the following:
In the first table add for the block of columns elements that might need an update: 2 blocks of columns, the first with the result of combining (the COMB-block) and the second with lookups from the 2nd table (the LOOKUP-block). For convenience of explaining I put the two tables in the same workbook on the sheets called table1 and table2
ProductNo | Product | Sku | Price | Image | Thumb | Product_comb | Sku_comb | Price_comb | Image_comb | Thumb_comb | Product_lookup | Sku_lookup | Price_lookup | Image_lookup | Thumb_lookup
Now start with formulas in the LOOKUP-block, use VLOOKUP(), such as this one for the *Product_vlookup* column:
=IFERROR(VLOOKUP($A2,table2!$A:B,COLUMNS(table2!$A:B),FALSE),"")
The IFERROR is for the case the product in table1 cannot be found in table2
For the formulas in the COMB-block the following will prefer the table 2 result over the table 1 result. As VLOOKUP of a matching ProductNo with an empty Element (for example for the Image) will result in a 0 (zero) returned all zeroes are regarded false lookup results as well. This is the script for the *Product_comb* column:
=IF(OR(ISBLANK(L2),L2=0),B2,L2)
As a final step to identify the products that changed you can either add a column that compared the original value with the _comb value:
=AND(B2=G2,C2=H2,D2=I2,E2=J2,F2=K2) (this returns true for no changed columns and false for any changed column)
Or use conditional formatting on each element separately or on the combination as the AND() formula shows.
As a final step in your process of updating you could copy all records from the COMB-block and paste it over the original elements.
If you have any further questions please ask.

Resources