Forum Discussion
Create a new column based on distinct result
Hi Jimmy801 ,
Good day.
Apology on that. The table was created by using this formula in excel:
"Per Original Unique Reference, if Spend Expense Amount (USD) based on Original (Y) is greater than Sum of Amount in Question, then value is equal the Spend Expense Amount. Otherwise, Sum of Amount in Question."
To illustrate, for example:
| ORIGINAL UNIQUE REFERENCE | # (sequence per line item, i.e. 1,2,3) of Inserted Line | NEW UNIQUE REFERENCE | ORIGINAL (Y) | Customer Name | Spend - Expense Amount (USD) | AMOUNT IN QUESTION | SPECIFIC AUDIT ISSUE | Current Audit Status |
| OrigUniqRef_01 | OrigUniqRef_01 | Y | Customer A | 1,200.00 | 1,200.00 | Expense for Clarification | With Issue | |
| OrigUniqRef_01 | 1 | OrigUniqRef_01.L1 | Customer A | 1,200.00 | 1,200.00 | Business Purpose Not Provided | With Issue | |
| OrigUniqRef_01 | 2 | OrigUniqRef_01.L2 | Customer A | 1,200.00 | 1,000.00 | Only Credit Card Slip/Statement is provided. | With Issue | |
| OrigUniqRef_01 | 3 | OrigUniqRef_01.L3 | Customer A | 1,200.00 | 1,200.00 | No Time Charges | With Issue |
The Spend Amount in (Y) is = 1200
Sum Amount in Question = 4600
Then, for this Uniq Ref#, the audit result amount will show = 1200. (Because the original amount for this particular Row is 1200 only).
However, if there are errors in our formula, we check the audited file and edit it manually. For another example,
| ORIGINAL UNIQUE REFERENCE | # (sequence per line item, i.e. 1,2,3) of Inserted Line | NEW UNIQUE REFERENCE | ORIGINAL (Y) | Customer Name | Spend - Expense Amount (USD) | AMOUNT IN QUESTION | SPECIFIC AUDIT ISSUE | Current Audit Status |
| OrigUniqRef_02 | OrigUniqRef_02 | Y | Customer B | 1,500.00 | 900.00 | Receipt not provided | With Issue | |
| OrigUniqRef_02 | 1 | OrigUniqRef_02.L1 | Customer B | 1,500.00 | 900.00 | Expense for Clarification | With Issue |
The Spend Amount in (Y) is = 1500
Sum Amount in Question = 1800
Technically, the amount must appear only is 900 because the only amount with raised issue is the receipt with 900 in amount. However, it appears wrong if we use the formula we created for this Audit Result column that is why other rows with the same kind of scenario, we edit it and correct it manually.
I hope I got this one as answer to your question. 🙂
Thanks and regards,
Echo
Hi Jimmy801
Good day.
Just to add, any suggestion is open if you have as we are still on our process of developing our report team.
Thanks
- Jimmy8016 years ago
Community 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- Anonymous6 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
- Anonymous6 years agoNot applicable
Hi Jimmy801
Good day.
I already tried copy-paste the codes. I already got the idea but there was a proble. See image and notes below:
From there, i have noticed that for Orig Ref 02, it showed 1500 which should be 900 only. Because the only amount with issue is 900 from the 1500USD receipted. Altho, as you can see on the Audited File I attached earlier, it came out with two rows because it resulted to a 2 audit issues.
Thanks for the help again in advance.
Echo,
- Jimmy8016 years ago
Community Champion
Hello Anonymous
well, the first question about the code... .this is a code, created from Power Query when you input the data manually. Function is called "Enter data".
About the calculation itself. You stated this conditions
f Spend Expense Amount (USD) based on Original (Y) is greater than Sum of Amount in Question, then value is equal the Spend Expense Amount. Otherwise, Sum of Amount in Question."Spend Expense Amount of Ref_2 = 1500
Sum of Amount in question = 900 + 900 = 1800
in your condition this is untrue and therefore the second part should be applied that is Sum of Amount in Question and this is 1800
I just checked my code and I saw that I inverted the calculations.... So I can not understand how in this circumstances 900 could be a result. Can you explain how how the sum-function should work?
here the correct code
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.Max(group[#"Spend - Expense Amount (USD)"]) else List.Sum(group[AMOUNT IN QUESTION]) , type number}}) in #"Grouped Rows"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