Thanks for that
I have attached code so far.
However what I really want to do in the Table.AddColumn is if on the First Occurance of Goods and Services Tax for a Branch I want to use Asset otherwise Liability. At present if a new Item Other Than Goods and Services Tax is imported then the Rank in the code might need to be 3 and >3.
let
Source = Excel.CurrentWorkbook(){[Name=“t_IMP_BSheetItems”]}[Content],
#“Changed Type” = Table.TransformColumnTypes(Source,{{“Source.Name”, type text}, {“BranchLine”, type text}, {“ThisYear”, Int64.Type}, {“LastYear”, Int64.Type}, {“SheetName”, type text}, {“SourceRowNumber”, Int64.Type}, {“Notes”, type any}}),
#“Reordered Columns” = Table.ReorderColumns(#“Changed Type”,{“Source.Name”, “SheetName”, “SourceRowNumber”, “BranchLine”, “ThisYear”, “LastYear”, “Notes”}),
#“Removed Other Columns” = Table.SelectColumns(#“Reordered Columns”,{“Source.Name”, “SheetName”, “BranchLine”, “ThisYear”, “LastYear”, “Notes”, “SourceRowNumber”}),
#“Reordered Columns1” = Table.ReorderColumns(#“Removed Other Columns”,{“Source.Name”, “BranchLine”, “ThisYear”, “LastYear”, “SheetName”, “SourceRowNumber”, “Notes”}),
#“Sorted Rows” = Table.Sort(#“Reordered Columns1”,{{“SourceRowNumber”, Order.Descending}}),
#“Grouped Rows” = Table.Group(#“Sorted Rows”, {“Source.Name”}, {{“Count”, each _, type table [Source.Name=text, BranchLine=text, ThisYear=number, LastYear=number, SheetName=text, SourceRowNumber=number, Notes=none]}}),
#“Added Custom” = Table.AddColumn(#“Grouped Rows”, “Custom”, each Table.AddIndexColumn([Count],“Rank”,1,1)),
#“Removed Other Columns2” = Table.SelectColumns(#“Added Custom”,{“Custom”}),
#“Expanded Custom” = Table.ExpandTableColumn(#“Removed Other Columns2”, “Custom”, {“Source.Name”, “BranchLine”, “ThisYear”, “LastYear”, “SheetName”, “SourceRowNumber”, “Notes”, “Rank”}, {“Source.Name”, “BranchLine”, “ThisYear”, “LastYear”, “SheetName”, “SourceRowNumber”, “Notes”, “Rank”}),
#“Added Custom1” = Table.AddColumn(#“Expanded Custom”, “GST A or L”, each if [BranchLine] = “Goods and Services Tax” and [Rank] = 2 then “Asset” else
if [BranchLine] = “Goods and Services Tax” and [Rank] > 2 then “Liability” else “”)
in
#“Added Custom1”