Add manual columns to power query without losing data on refresh

timcpugh
Lounger
Posts: 43
Joined: 06 Jul 2019, 05:43

Add manual columns to power query without losing data on refresh

Post by timcpugh »

Hello there, i've created the following power query however when i add columns with manual data, then refresh- i lose this data/or it moves to the wrong line. What changes are required to avoid this?

Current query:

Code: Select all

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Delegate System", type text}, {"Item No.", type text}, {"Item", type text}, {"Vendor Group", type text}, {"Vendor", type text}, {"Over Group", type text}, {"Major Group", type text}, {"Item Group", type text}, {"Cost Center/Store", type text}, {"Unit", type text}, {"ANNUAL QTY/UNIT", Int64.Type}, {"MANUFACTURER", type any}, {"REPLACE/KEEP  COMMENTS", type any}, {"STATE", type text}, {"Abco Code", Int64.Type}, {"Desc", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Delegate System", "Item", "Vendor Group", "Vendor", "Over Group", "Major Group", "Item Group", "Cost Center/Store", "Unit", "REPLACE/KEEP  COMMENTS", "STATE"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Abco Code", "Desc", "Item No.", "ANNUAL QTY/UNIT", "MANUFACTURER"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Reordered Columns",{"MANUFACTURER"}),
    #"Reordered Columns1" = Table.ReorderColumns(#"Removed Columns1",{"Abco Code", "Desc", "ANNUAL QTY/UNIT", "Item No."}),
    #"Grouped Rows" = Table.Group(#"Reordered Columns", {"Abco Code", "Desc"}, {{"Total_Qty", each List.Sum([#"ANNUAL QTY/UNIT"]), type nullable number}, {"Old_Codes", each Text.Combine(List.Distinct([#"Item No."]), ", "), type text}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Total_Qty", Order.Descending}})
in
    #"Sorted Rows"

User avatar
hamster
StarLounger
Posts: 58
Joined: 10 Mar 2021, 22:57

Re: Add manual columns to power query without losing data on refresh

Post by hamster »

post example of your anonymised source data , your table with additional columns and expected result
or attach excel file with these examples
Last edited by hamster on 10 Mar 2021, 23:25, edited 1 time in total.

User avatar
hamster
StarLounger
Posts: 58
Joined: 10 Mar 2021, 22:57

Re: Add manual columns to power query without losing data on refresh

Post by hamster »

you can try this

Code: Select all

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    TSC = Table.SelectColumns(Source,{"Abco Code", "Desc", "ANNUAL QTY/UNIT", "Item No."}),
    Group = Table.Group(TSC, {"Abco Code", "Desc"}, {{"Total_Qty", each List.Sum([#"ANNUAL QTY/UNIT"]), type nullable number}, {"Old_Codes", each Text.Combine(List.Distinct([#"Item No."]), ", "), type text}}),
    Type = Table.TransformColumnTypes(Group,{{"Abco Code", Int64.Type}, {"Desc", type text}, {"Total_Qty", Int64.Type}, {"Old_Codes", type text}}),
    Sort = Table.Sort(Type,{{"Total_Qty", Order.Descending}})
in
    Sort
but if it doesn't work see my previous post

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Add manual columns to power query without losing data on refresh

Post by HansV »

Welcome to Eileen's Lounge and thanks for helping out!
Best wishes,
Hans

User avatar
hamster
StarLounger
Posts: 58
Joined: 10 Mar 2021, 22:57

Re: Add manual columns to power query without losing data on refresh

Post by hamster »

@HansV
:grin: :grin: :grin:

timcpugh
Lounger
Posts: 43
Joined: 06 Jul 2019, 05:43

Re: Add manual columns to power query without losing data on refresh

Post by timcpugh »

hamster wrote:
10 Mar 2021, 23:19
post example of your anonymised source data , your table with additional columns and expected result
or attach excel file with these examples
See the example attached, and video to replicate the issue: https://www.dropbox.com/s/lcmx6xzps4itp ... 6.mp4?dl=0
You do not have the required permissions to view the files attached to this post.

User avatar
hamster
StarLounger
Posts: 58
Joined: 10 Mar 2021, 22:57

Re: Add manual columns to power query without losing data on refresh

Post by hamster »

this is completely different from what you wrote in the first post
so see this: https://exceleratorbi.com.au/self-refer ... wer-query/