Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I am new here and new to tech forums in general. I am not that technical so I have had zero luck in taking others' solutions and adapting to my situation. I have included the current code that I have for a query in Excel. I need to add a column that counts the number of times a serial number appears in the column labeled Serial Number, [Serial Number}] Please help.
let
Source = Excel.Workbook(File.Contents("C:\Users\mguckel\Documents\New Unscrubbed-Enrichment.xlsx"), null, true),
Table_crosstab_Sheet = Source{0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Table_crosstab_Sheet, [PromoteAllScalars=true]),
#"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"% Spared At Depot", "% Spare within 150 Miles Onhand", "Line", "% Spare Component Incoming", "TM - Sparing Score", "Actual Line End Date", "Asset Quantity Missing Site", "Backline Provider", "Is Line Expired", "Aging Label", "Is Outsourced ?", "MostRecentOrder ShipDate Label", "MostRecentOrder Order Number Label", "Hit Onhand Target", "Is Networking?", "Is Asset Line?", "Est. Server/Storage Enrichment %", "Asset Quantity Server/Storage", "CNTD Asset Number", "% Spared", "% Spared In Country", "TM - Sparing Score - Is Spared?", "Is Included In Sparing % ?", "Line Term", "Service From Location Has Error ?", "CountryCode For Summary", "__FilterEndCustomerTop200", "Component Qty", "Asset Quantity", "Asset Quantity Networking", "Has Spare Onhand", "Is Covered ?", "CNTD Installed Component", "Covered Component Quantity", "ComponentQuantityPerAsset", "Contract Quantity", "Cont Line ID", "ContractLineAddress SAP Plant Key", "ContractLine DrivingDistance Miles", "ContractLine DrivingTime Minutes", "CountryCode", "CtDistComponentPerAsset", "CtDistMaterialGroupPerAsset", "DONOTUSE__EstMonthlyRateUSD", "ERP", "Has Spare Within 150 Miles?", "Has Spare In Country ? ", "Has Spare Incoming to Country", "Has Spare Incoming", "Hit Enrichment Target", "Hit TM - Sparing Target", "Hit In Country Target", "Hub With Inventory", "LastUpdateDate", "Line Status", "Location Key", "Min Contract SLA From Demand", "Nearest SAPFSL Distance", "Nearest SAPFSL", "Number of Records", "Record Level (group)", "Is Covered", "Sap Id", "Sla Label", "Description", "Matgrp (group)", "Manf", "StockStatus", "AZ AV INV", "BLR AV INV", "Avg Aging HFR/MFR", "Status", "Asset Description", "Continent", "NC AV INV", "SBA AV INV", "TX AV INV", "HubOption1", "HubOption2", "Asset SKU", "Most Recent Order", "End Customer", "ContractLineAddress WhseID", "AMS AV INV", "Currency", "KY_AV_INV", "SNG AV INV"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Customer Name", "Ship To Customer", "Contract ID", "Actual Line Start Date", "ContractLine Address1", "ContractLine City", "ContractLine State", "ContractLine Zip", "Contractline CountryName", "Contractline CountryCode", "Region", "Est Monthly Rate", "SLA Term Name", "Parts Provider", "External3PSLaborProvider", "Component", "SLA Description", "Contract Line Create Date", "Service From Location", "MFG Name", "MostRecentOrder OrderNumber", "MostRecentOrder Product", "MostRecentOrder ShipDate", "Owner", "Record Level", "Serial Number", "Site Audit Create Date", "Site Audit Description", "Site Audit Incident Number", "Site Audit Last Event Code", "Site Audit Status", "Component Description", "Matgrp", "Aging", "FailureRateCategory", "StockStatusDescription", "Sub Inventory And Incoming", "Incoming In Country", "Incoming 250KM", "Incoming With Subs", "Inventory And Incoming", "Inventory Onhand In Country", "Inventory Onhand Within 250KM", "Inventory Onhand", "Component Quantity Site Audit Status ADDED", "Component Quantity Site Audit Status EXPECTED", "Component Quantity Site Audit Status FOUND", "Component Quantity Site Audit Status OTHER"}),
#"Reordered Columns1" = Table.ReorderColumns(#"Reordered Columns",{"Customer Name", "Ship To Customer", "Contract ID", "Actual Line Start Date", "ContractLine Address1", "ContractLine City", "ContractLine State", "ContractLine Zip", "Contractline CountryName", "Contractline CountryCode", "Region", "Est Monthly Rate", "SLA Term Name", "SLA Description", "Parts Provider", "External3PSLaborProvider", "Contract Line Create Date", "Service From Location", "Serial Number", "Record Level", "MFG Name", "Component Description", "Component", "Matgrp", "MostRecentOrder OrderNumber", "MostRecentOrder Product", "MostRecentOrder ShipDate", "Owner", "Site Audit Create Date", "Site Audit Description", "Site Audit Incident Number", "Site Audit Last Event Code", "Site Audit Status", "Aging", "FailureRateCategory", "StockStatusDescription", "Inventory Onhand", "Incoming With Subs", "Inventory And Incoming", "Sub Inventory And Incoming", "Inventory Onhand In Country", "Incoming In Country", "Inventory Onhand Within 250KM", "Incoming 250KM", "Component Quantity Site Audit Status ADDED", "Component Quantity Site Audit Status EXPECTED", "Component Quantity Site Audit Status FOUND", "Component Quantity Site Audit Status OTHER"})
in
#"Reordered Columns1"
The code below has a line that groups on serial number, counts the rows and also brings in all data. It does not require the Reorder column steps and these were taken out. You should be able to paste this data "as-is" into your existing advanced editor.
let
Source = Excel.Workbook(File.Contents("C:\Users\mguckel\Documents\New Unscrubbed-Enrichment.xlsx"), null, true),
Table_crosstab_Sheet = Source{0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Table_crosstab_Sheet, [PromoteAllScalars=true]),
#"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"% Spared At Depot", "% Spare within 150 Miles Onhand", "Line", "% Spare Component Incoming", "TM - Sparing Score", "Actual Line End Date", "Asset Quantity Missing Site", "Backline Provider", "Is Line Expired", "Aging Label", "Is Outsourced ?", "MostRecentOrder ShipDate Label", "MostRecentOrder Order Number Label", "Hit Onhand Target", "Is Networking?", "Is Asset Line?", "Est. Server/Storage Enrichment %", "Asset Quantity Server/Storage", "CNTD Asset Number", "% Spared", "% Spared In Country", "TM - Sparing Score - Is Spared?", "Is Included In Sparing % ?", "Line Term", "Service From Location Has Error ?", "CountryCode For Summary", "__FilterEndCustomerTop200", "Component Qty", "Asset Quantity", "Asset Quantity Networking", "Has Spare Onhand", "Is Covered ?", "CNTD Installed Component", "Covered Component Quantity", "ComponentQuantityPerAsset", "Contract Quantity", "Cont Line ID", "ContractLineAddress SAP Plant Key", "ContractLine DrivingDistance Miles", "ContractLine DrivingTime Minutes", "CountryCode", "CtDistComponentPerAsset", "CtDistMaterialGroupPerAsset", "DONOTUSE__EstMonthlyRateUSD", "ERP", "Has Spare Within 150 Miles?", "Has Spare In Country ? ", "Has Spare Incoming to Country", "Has Spare Incoming", "Hit Enrichment Target", "Hit TM - Sparing Target", "Hit In Country Target", "Hub With Inventory", "LastUpdateDate", "Line Status", "Location Key", "Min Contract SLA From Demand", "Nearest SAPFSL Distance", "Nearest SAPFSL", "Number of Records", "Record Level (group)", "Is Covered", "Sap Id", "Sla Label", "Description", "Matgrp (group)", "Manf", "StockStatus", "AZ AV INV", "BLR AV INV", "Avg Aging HFR/MFR", "Status", "Asset Description", "Continent", "NC AV INV", "SBA AV INV", "TX AV INV", "HubOption1", "HubOption2", "Asset SKU", "Most Recent Order", "End Customer", "ContractLineAddress WhseID", "AMS AV INV", "Currency", "KY_AV_INV", "SNG AV INV"}),
#"Grouped Rows" = Table.Group(#"Removed Columns", {"Serial Number"}, {{"AllData", each _, type table [Customer Name=number, Ship To Customer=number, Contract ID=number, Actual Line Start Date=number, ContractLine Address1=number, ContractLine City=number, ContractLine State=number, ContractLine Zip=number, Contractline CountryName=number, Contractline CountryCode=number, Region=number, Est Monthly Rate=number, SLA Term Name=number, Parts Provider=number, External3PSLaborProvider=number, Component=number, SLA Description=number, Contract Line Create Date=number, Service From Location=number, MFG Name=number, MostRecentOrder OrderNumber=number, MostRecentOrder Product=number, MostRecentOrder ShipDate=number, Owner=number, Record Level=number, Serial Number=number, Site Audit Create Date=number, Site Audit Description=number, Site Audit Incident Number=number, Site Audit Last Event Code=number, Site Audit Status=number, Component Description=number, Matgrp=number, Aging=number, FailureRateCategory=number, StockStatusDescription=number, Sub Inventory And Incoming=number, Incoming In Country=number, Incoming 250KM=number, Incoming With Subs=number, Inventory And Incoming=number, Inventory Onhand In Country=number, Inventory Onhand Within 250KM=number, Inventory Onhand=number, Component Quantity Site Audit Status ADDED=number, Component Quantity Site Audit Status EXPECTED=number, Component Quantity Site Audit Status FOUND=number, Component Quantity Site Audit Status OTHER=number]}, {"SerialNumberCount", each Table.RowCount(_), type number}}),
#"Removed Columns1" = Table.RemoveColumns(#"Grouped Rows",{"Serial Number"}),
#"Expanded AllData" = Table.ExpandTableColumn(#"Removed Columns1", "AllData", {"Customer Name","Ship To Customer","Contract ID","Actual Line Start Date","ContractLine Address1","ContractLine City","ContractLine State","ContractLine Zip","Contractline CountryName","Contractline CountryCode","Region","Est Monthly Rate","SLA Term Name","SLA Description","Parts Provider","External3PSLaborProvider","Contract Line Create Date","Service From Location","Serial Number","Record Level","MFG Name","Component Description","Component","Matgrp","MostRecentOrder OrderNumber","MostRecentOrder Product","MostRecentOrder ShipDate","Owner","Site Audit Create Date","Site Audit Description","Site Audit Incident Number","Site Audit Last Event Code","Site Audit Status","Aging","FailureRateCategory","StockStatusDescription","Inventory Onhand","Incoming With Subs","Inventory And Incoming","Sub Inventory And Incoming","Inventory Onhand In Country","Incoming In Country","Inventory Onhand Within 250KM","Incoming 250KM","Component Quantity Site Audit Status ADDED","Component Quantity Site Audit Status EXPECTED","Component Quantity Site Audit Status FOUND","Component Quantity Site Audit Status OTHER"})
in
#"Expanded AllData"
Hi @Anonymous ,
How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?
Best regards,
Hi @Anonymous ,
We can try to use Table.AddColumn and Table.RowCount functions to meet your requirement, all the queries are here:
let
Source = Excel.Workbook(File.Contents("C:\Users\mguckel\Documents\New Unscrubbed-Enrichment.xlsx"), null, true),
Table_crosstab_Sheet = Source{0}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Table_crosstab_Sheet, [PromoteAllScalars=true]),
#"Removed Columns" = Table.RemoveColumns(#"Promoted Headers",{"% Spared At Depot", "% Spare within 150 Miles Onhand", "Line", "% Spare Component Incoming", "TM - Sparing Score", "Actual Line End Date", "Asset Quantity Missing Site", "Backline Provider", "Is Line Expired", "Aging Label", "Is Outsourced ?", "MostRecentOrder ShipDate Label", "MostRecentOrder Order Number Label", "Hit Onhand Target", "Is Networking?", "Is Asset Line?", "Est. Server/Storage Enrichment %", "Asset Quantity Server/Storage", "CNTD Asset Number", "% Spared", "% Spared In Country", "TM - Sparing Score - Is Spared?", "Is Included In Sparing % ?", "Line Term", "Service From Location Has Error ?", "CountryCode For Summary", "__FilterEndCustomerTop200", "Component Qty", "Asset Quantity", "Asset Quantity Networking", "Has Spare Onhand", "Is Covered ?", "CNTD Installed Component", "Covered Component Quantity", "ComponentQuantityPerAsset", "Contract Quantity", "Cont Line ID", "ContractLineAddress SAP Plant Key", "ContractLine DrivingDistance Miles", "ContractLine DrivingTime Minutes", "CountryCode", "CtDistComponentPerAsset", "CtDistMaterialGroupPerAsset", "DONOTUSE__EstMonthlyRateUSD", "ERP", "Has Spare Within 150 Miles?", "Has Spare In Country ? ", "Has Spare Incoming to Country", "Has Spare Incoming", "Hit Enrichment Target", "Hit TM - Sparing Target", "Hit In Country Target", "Hub With Inventory", "LastUpdateDate", "Line Status", "Location Key", "Min Contract SLA From Demand", "Nearest SAPFSL Distance", "Nearest SAPFSL", "Number of Records", "Record Level (group)", "Is Covered", "Sap Id", "Sla Label", "Description", "Matgrp (group)", "Manf", "StockStatus", "AZ AV INV", "BLR AV INV", "Avg Aging HFR/MFR", "Status", "Asset Description", "Continent", "NC AV INV", "SBA AV INV", "TX AV INV", "HubOption1", "HubOption2", "Asset SKU", "Most Recent Order", "End Customer", "ContractLineAddress WhseID", "AMS AV INV", "Currency", "KY_AV_INV", "SNG AV INV"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Customer Name", "Ship To Customer", "Contract ID", "Actual Line Start Date", "ContractLine Address1", "ContractLine City", "ContractLine State", "ContractLine Zip", "Contractline CountryName", "Contractline CountryCode", "Region", "Est Monthly Rate", "SLA Term Name", "Parts Provider", "External3PSLaborProvider", "Component", "SLA Description", "Contract Line Create Date", "Service From Location", "MFG Name", "MostRecentOrder OrderNumber", "MostRecentOrder Product", "MostRecentOrder ShipDate", "Owner", "Record Level", "Serial Number", "Site Audit Create Date", "Site Audit Description", "Site Audit Incident Number", "Site Audit Last Event Code", "Site Audit Status", "Component Description", "Matgrp", "Aging", "FailureRateCategory", "StockStatusDescription", "Sub Inventory And Incoming", "Incoming In Country", "Incoming 250KM", "Incoming With Subs", "Inventory And Incoming", "Inventory Onhand In Country", "Inventory Onhand Within 250KM", "Inventory Onhand", "Component Quantity Site Audit Status ADDED", "Component Quantity Site Audit Status EXPECTED", "Component Quantity Site Audit Status FOUND", "Component Quantity Site Audit Status OTHER"}),
#"Reordered Columns1" = Table.ReorderColumns(#"Reordered Columns",{"Customer Name", "Ship To Customer", "Contract ID", "Actual Line Start Date", "ContractLine Address1", "ContractLine City", "ContractLine State", "ContractLine Zip", "Contractline CountryName", "Contractline CountryCode", "Region", "Est Monthly Rate", "SLA Term Name", "SLA Description", "Parts Provider", "External3PSLaborProvider", "Contract Line Create Date", "Service From Location", "Serial Number", "Record Level", "MFG Name", "Component Description", "Component", "Matgrp", "MostRecentOrder OrderNumber", "MostRecentOrder Product", "MostRecentOrder ShipDate", "Owner", "Site Audit Create Date", "Site Audit Description", "Site Audit Incident Number", "Site Audit Last Event Code", "Site Audit Status", "Aging", "FailureRateCategory", "StockStatusDescription", "Inventory Onhand", "Incoming With Subs", "Inventory And Incoming", "Sub Inventory And Incoming", "Inventory Onhand In Country", "Incoming In Country", "Inventory Onhand Within 250KM", "Incoming 250KM", "Component Quantity Site Audit Status ADDED", "Component Quantity Site Audit Status EXPECTED", "Component Quantity Site Audit Status FOUND", "Component Quantity Site Audit Status OTHER"}),
AddColumn = Table.AddColumn(#"Reordered Columns1","Same Serial Number Count", each let SN = [Serial Number] in Table.RowCount(Table.SelectRows(#"Reordered Columns1", each [Serial Number] = SN)))
in
AddColumn
Best regards,