gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,347
- Office Version
- 365
- Platform
- Windows
Im am pivoted a column and creating new columns from the values. In the column that is being Pivoted there may or may not be the values "Vendor NRE" and/or "Excess Material"
The Pivot works as expected.
What I am trying to do is create a "Vendor NRE" and/or an "Excess Material" column if the Pivot function did not result in creating these.
So I added the SQL code to add them - but its not working
In my test run - there is the value "Excess Material" in the Resource Type - so it gets created at that line of code
But for some reason the next line removes the newly created column "Excess Material"
This does create a Vendor NRE column and the line of code after that does create an Excess Material Code
But my problem is the Column that is created at the Pivot step goes away. I dont want it to. I only want to Add Columns if they dont previously exist.
Any help is appreciated
The Pivot works as expected.
What I am trying to do is create a "Vendor NRE" and/or an "Excess Material" column if the Pivot function did not result in creating these.
So I added the SQL code to add them - but its not working
In my test run - there is the value "Excess Material" in the Resource Type - so it gets created at that line of code
Power Query:
#"Pivoted Column" = Table.Pivot(#"Removed Other Columns", List.Distinct(#"Removed Other Columns"[#"Resource Type"]), "Resource Type", "Amount", List.Sum),
Power Query:
#"Added Custom" = try Table.AddColumn(#"Filtered Rows", "Vendor NRE", each null, Currency.Type) otherwise #"Filtered Rows",
But my problem is the Column that is created at the Pivot step goes away. I dont want it to. I only want to Add Columns if they dont previously exist.
Any help is appreciated
Power Query:
let
// Reference Table from CMCS_BoM_MakeTable
Source = CMCS_BoM_MakeTable,
#"Filtered Rows" = Table.SelectRows(Source, each ([Type] = "Assoc Cost")),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"TASK ID", "Task Qty", "Column1", "Column2", "Column3", "WBS", "Type", "Assembly/Part", "Column4", "Assembly/Part Description", "Make/Buy", "UM", "Base Unit Cost", "Escalation Factor", "Quantity", "Extended Task Qty", "Delivery/Ship Qty", "Extended Qty", "Unit Cost", "Extended Cost", "Cost Type", "Cost Subcategory", "Cost Source", "Cost From Date", "Cost To Date", "Cost Esc. Base Date", "Cost Escalation ID", "Commodity", "Vendor", "Cost Lead Time", "Rule", "SimTo For Part", "Task Description", "PART NUMBER", "MTRL CONSOLIDATION", "OBS", "Material / Reference", "Resource", "CLIN", "SUMMARY", "Resource Type", "Amount"}),
#"Removed Other Columns" = Table.SelectColumns(#"Reordered Columns",{"Assembly/Part", "TASK ID", "Assembly/Part Description", "Material / Reference", "Resource", "Resource Type", "Amount"}),
// Pivot is where a Vendor NRE and/or Excess Material column is created if "Vendor NRE" and/or "Excess Material" is listed in the Resource Type Column
#"Pivoted Column" = Table.Pivot(#"Removed Other Columns", List.Distinct(#"Removed Other Columns"[#"Resource Type"]), "Resource Type", "Amount", List.Sum),
// Add the Column Vendor NRE is it does not exist
#"Added Custom" = try Table.AddColumn(#"Filtered Rows", "Vendor NRE", each null, Currency.Type) otherwise #"Filtered Rows",
// Add the Column Excess Material is it does not exist
#"Added Custom1" = try Table.AddColumn(#"Added Custom", "Excess Material", each null, Currency.Type) otherwise #"Added Custom",
#"Replaced NRE null w0" = Table.ReplaceValue(#"Added Custom1",null,0,Replacer.ReplaceValue,{"Vendor NRE"}),
#"Replaced Excess null w0" = Table.ReplaceValue(#"Replaced NRE null w0",null,0,Replacer.ReplaceValue,{"Excess Material"}),
#"Changed Type" = Table.TransformColumnTypes(#"Replaced Excess null w0",{{"Vendor NRE", Currency.Type}, {"Excess Material", Currency.Type}})
in
#"Changed Type"
Last edited by a moderator: