Forum Discussion
customize column to choose from duplicated rows in power Query
- 3 years ago
Hi osama_ayoub,
As you merged the tables PBI allocated a set of records for each matching line in the source table (this is why it is important/more convenient to merge Requests with Avail rather then vise versa):
if you click on the cell (not on the Table itself) in the Available column you will see how the available quantities are assigned to the requested ones.
Then we add a column that is actually a set of the available quantities with how many of them we can allocate to fullfill the request. The majic happens in this fuction:
f = (t as table, req as number)=> let avail = Number.From(t{0}[Available in Material Code]), res = if avail > req or Table.RowCount(t) = 1 then {Record.AddField(t{0}, "take", List.Min({req, avail}))} else {Record.AddField(t{0}, "take", avail)} & @f(Table.Skip(t), req - avail) in resIt gets two parameters:
- t - a table of quanties available for this product,
- req - required quantity
In the funciton:
- avail takes the first row of the table of available materials passed to the funciton
- then we check if the available quantity on this row is sufficient to fulfill the required quantity passed to the function:
- If this is sufficient, it adds a field (which later converted to ta column in the output table) and sets its value = req
- If there is only one row left in the column, there is no point going any further and we just allocate the lesser of req and avail , i.e. trying to fullfill the request as much as possible
- Otherwise, we take as much as we can on this "supply" row and call the function again, this time passing all but the first line in the "supply" table (cause this is already been "taken") and the portion of "required" amount (reduced by the volumes fullfuilled by this "supply" row.
This may be a bit unclear, but it hopefully it can make sense if you "walk the steps" in the function, bearing in mind that it recursively calls itself with demonishing number of lines and required quantities until either "supply" rows will be depleted or the entire required amount supplied.
Kind regards,
John
hi,
for the planning code Main00357 the required quantity is 100 and there are 2 rows under the same planning code so we go to the first row and check the available if it is equal or greater than the required quantity we take the required quantity from first row and skip the second row but if the quantity in the second row is less than the required we take all the quantity in the first row and go to the second row and take it untill we complete our required quantity.
I hope I could explain it well
Regards
- edhans3 years ago
Community Champion
Again:
- Need data
- Need example of your desired output. You know the old saying, a picture is worth a thousand words.
How to get good help fast. Help us help you.
How To Ask A Technical Question If you Really Want An Answer
How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.- osama_ayoub3 years ago
Helper III
https://docs.google.com/spreadsheets/d/1_UWWE5pZdhdgIsmCxueDqt_RjP01V816/edit#gid=1335661612
I have attached excel file, what I want is a new column to determine how much should I take from [available in Material code] to get the [required from planning code]
there are duplicated values in column [required from planning code] so I want only one value from this duplicated value.
thanks for trying to help me
Regards