Forum Discussion
Anonymous
6 years agoNot applicable
Create a new column based on distinct result
Hi, Good day. I need some help to get an accurate audit result from a given audited data. But first, let me share to your our audit process and give you samples. See details as follows: 1...
Jimmy801
6 years agoCommunity Champion
Hello Anonymous
try out this solution. It uses Table.Group and depending on your indicated conditions, applies different calculations.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZPRSsMwFIZf5dDr0qUZXuzSBS8E2camiIwhYT3dDrRJTNIx38Zn8cnMxSZoI81NpclFkj/w/eTrdpstLR2eFL2tsX5lZZZnYfT2XsIUnfO6RQu3YfH58fcHZc4ZKxgbyP1M3p0NKodQawuikZZq2ktPWoWzZ/JHuHeuw2yXR5DLHnPxcKkyMvW8c6TQOVh11uiAv9AeVlafqMIqgZxHyPmY5OyaXKrmHYTFijwIaSvYNGQmGy89tqg8kANz6VEkFJlGikz/5QkWGh6pRRBHaQ/oBlh5xHD+2/D5MOhNGuj3jdk1v8Y9kvGggigmTRQeU5z3FR8TO/X33H0B", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"ORIGINAL UNIQUE REFERENCE" = _t, #"# (sequence per line item, i.e. 1,2,3) of Inserted Line " = _t, #"NEW UNIQUE REFERENCE" = _t, #"ORIGINAL (Y)" = _t, #"Customer Name" = _t, #" Spend - Expense Amount (USD) " = _t, #" AMOUNT IN QUESTION " = _t, SPECIFIC = _t, #"Current Audit Status" = _t]),
#"Renamed Columns1" = Table.RenameColumns(Source,{{" Spend - Expense Amount (USD) ", "Spend - Expense Amount (USD)"}}),
#"Renamed Columns" = Table.RenameColumns(#"Renamed Columns1",{{" AMOUNT IN QUESTION ", "AMOUNT IN QUESTION"}}),
Trans = Table.TransformColumns(#"Renamed Columns",{{"AMOUNT IN QUESTION", each Number.From(_, "en-US"), Int64.Type}, {"Spend - Expense Amount (USD)", each Number.From(_, "en-US"), Int64.Type}}),
#"Grouped Rows" = Table.Group(Trans, {"ORIGINAL UNIQUE REFERENCE"}, {{"Custom", (group)=> if List.Max(group[#"Spend - Expense Amount (USD)"])> List.Sum(group[AMOUNT IN QUESTION]) then List.Sum(group[AMOUNT IN QUESTION]) else List.Max(group[#"Spend - Expense Amount (USD)"]) , type number}})
in
#"Grouped Rows"
Copy paste this code to the advanced editor in a new blank query to see how the solution works.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy
Anonymous
6 years agoNot applicable
Hi Jimmy801 ,
Good day.
This is big help. Will try this one and give you feedbacks asap.
However, I find hard to understand this portion,
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("vZPRSsMwFIZf5dDr0qUZXuzSBS8E2camiIwhYT3dDrRJTNIx38Zn8cnMxSZoI81NpclFkj/w/eTrdpstLR2eFL2tsX5lZZZnYfT2XsIUnfO6RQu3YfH58fcHZc4ZKxgbyP1M3p0NKodQawuikZZq2ktPWoWzZ/JHuHeuw2yXR5DLHnPxcKkyMvW8c6TQOVh11uiAv9AeVlafqMIqgZxHyPmY5OyaXKrmHYTFijwIaSvYNGQmGy89tqg8kANz6VEkFJlGikz/5QkWGh6pRRBHaQ/oBlh5xHD+2/D5MOhNGuj3jdk1v8Y9kvGggigmTRQeU5z3FR8TO/X33H0B"
Would you help with this?
Thanks and regards,
Echo