SOLVED

Adding a column with custom values to a Power Query

%3CLINGO-SUB%20id%3D%22lingo-sub-2045235%22%20slang%3D%22en-US%22%3EAdding%20a%20column%20with%20custom%20values%20to%20a%20Power%20Query%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2045235%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20in%20Sheet1%20a%20table%20tProducts%20with%20products%20and%20quantities%20sold%20from%20the%20last%206%20months%20(coming%20from%20SQL%20query%20from%20the%20company%20ERP).%3C%2FP%3E%3CP%3EI%20now%20want%20to%20make%20a%20custom%20table%20tSS%20where%20I%20assign%20to%20each%20product%20a%20binary%20%22strategic%20stock%22%20value%3A%201%20or%200.%20The%20product%20list%20in%20this%20table%20needs%20to%20come%20from%20tProducts%20(ERP)%20and%20update%20automatically%2C%20so%20that%20when%20new%20products%20are%20added%20in%20tProducts%2C%20they%20appear%20in%20tSS%20(without%20a%200%20or%201%20value%20of%20course%2C%20since%20I%20will%20add%20these%20manually).%3C%2FP%3E%3CP%3EFinally%2C%20I%20want%20to%20combine%20the%20two%20tables%20in%20a%20third%20table%20tResult%2C%20where%20I%20want%20only%20the%20products%20which%20have%20a%20tSS%20%22strategic%20stock%22%20value%20of%201%20to%20appear%2C%20and%20calculate%20a%20minimum%20stock%20value%20based%20on%20the%20sold%20quantities%20of%20last%20six%20months%2C%20using%20a%20formula.%20(Let's%20say%2C%20for%20the%20sake%20of%20simplicity%2C%20half%20that%20value).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20would%20be%20the%20best%20strategy%20to%20use%3F%20I'm%20more%20or%20less%20comfortable%20with%20Power%20Query%2C%20but%20not%20sure%20how%20to%20build%20up%20tSS.%3CBR%20%2F%3EAttached%20a%20basic%20workbook%20with%20a%20(fictional)%20example%20tProducts.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2045235%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2045257%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20a%20column%20with%20custom%20values%20to%20a%20Power%20Query%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2045257%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F863782%22%20target%3D%22_blank%22%3E%40bartvana%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20may%20use%20technique%20described%20here%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fexceleratorbi.com.au%2Fself-referencing-tables-power-query%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3ESelf%20Referencing%20Tables%20in%20Power%20Query%20-%20Excelerator%20BI%3C%2FA%3E%26nbsp%3Bto%20add%20custom%20column%20with%201%2F0%20to%20tProducts%20table%20(or%20to%20reference%20on%20it).%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2045319%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20a%20column%20with%20custom%20values%20to%20a%20Power%20Query%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2045319%22%20slang%3D%22en-US%22%3EI%20have%20the%20impression%20this%20won't%20work%20for%20me.%20The%20original%20data%20I%20use%20to%20make%20tProducts%20doesn't%20have%20an%20ID%20column.%20I%20can%20add%20one%20of%20course%20in%20Power%20Query.%20But%20if%20the%20list%20of%20products%20in%20the%20ERP%20system%20changes%20(where%20I%20get%20tProducts%20from)%2C%20then%20the%20ID's%20I%20add%20in%20Power%20Query%20will%20reference%20other%20products.%20(I%20don't%20know%20if%20I%20make%20myself%20clear%3F%20Imagine%20the%20second%20product%20in%20the%20ERP%20system%20disappears.%20Power%20Query%20adds%20an%20ID%20column.%20ID5%20will%20now%20reference%20the%20product%20that%20previously%20was%20ID6).%3C%2FLINGO-BODY%3E
Contributor

I have in Sheet1 a table tProducts with products and quantities sold from the last 6 months (coming from SQL query from the company ERP).

I now want to make a custom table tSS where I assign to each product a binary "strategic stock" value: 1 or 0. The product list in this table needs to come from tProducts (ERP) and update automatically, so that when new products are added in tProducts, they appear in tSS (without a 0 or 1 value of course, since I will add these manually).

Finally, I want to combine the two tables in a third table tResult, where I want only the products which have a tSS "strategic stock" value of 1 to appear, and calculate a minimum stock value based on the sold quantities of last six months, using a formula. (Let's say, for the sake of simplicity, half that value).

 

What would be the best strategy to use? I'm more or less comfortable with Power Query, but not sure how to build up tSS.
Attached a basic workbook with a (fictional) example tProducts.

5 Replies

@bartvana 

You may use technique described here Self Referencing Tables in Power Query - Excelerator BI to add custom column with 1/0 to tProducts table (or to reference on it).

I have the impression this won't work for me. The original data I use to make tProducts doesn't have an ID column. I can add one of course in Power Query. But if the list of products in the ERP system changes (where I get tProducts from), then the ID's I add in Power Query will reference other products. (I don't know if I make myself clear? Imagine the second product in the ERP system disappears. Power Query adds an ID column. ID5 will now reference the product that previously was ID6).

@bartvana 

Yes, you need to have unique ID (which could be product name itself) for that. But you need to have it in any case, otherwise how to recognize the products in the list which have no id, same names but perhaps only some other parameters are different? If 1/0 is related only to product name and nothing else, you may create another table with unique product names and use it.

@Sergei Baklan The product names are unique and can serve as ID. But they're not "mathematical" and the list changes regularly (additions and deletions).
Taking this into account, how would you solve this in my simple example workbook?

So in sheet2 I need the list of products where I can manually add the SS value (0 or 1). But let's say prod02 is deleted in sheet1 and prod15 is added, how can sheet2 update with the new list of products without losing the SS values already assigned to still existing products?

best response confirmed by bartvana (Contributor)
Solution

@bartvana 

Please check in attached. I trim and lowcase product names to use them as ID, but if you data is clean it's not necessary.