Power Query Mcode to add custom columns based on values in another column

sadavies2906

New Member
Joined
Feb 5, 2011
Messages
45
I currently have the following output generated by a series of power queries using M code. I can make the changes within Excel once I output the results but would really like to get everything done within the query.

  1. Need to get a column that auto generated a sequential number based on the value within the Order column that increment when it come across a new value.
  2. When the incremented number is found more than once to populate a second column with the value "SHORTAGE" else populate with "SHORTAGE FREE"

1682285053503.png
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],  //Change Table2 to your table name
    Group = Table.Group(Source, {"Order"}, {{"x", each Table.AddColumn(_, "Shortage Status", (x)=> (if Table.RowCount(_)=1 then "Shortage Free" else "Shortage"))}}),
    AddIndex = Table.AddIndexColumn(Group, "Seq", 1, 1, Int64.Type),
    Expand = Table.ExpandTableColumn(AddIndex, "x", {"Shortage Status", "Material Type"}),
    Reorder = Table.ReorderColumns(Expand,{"Seq", "Order", "Shortage Status", "Material Type"})
in
    Reorder
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top