Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not 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. We extracted on our system the new set of Unaudited Data for the month. And it looks like this:

Audit_Sample_01.PNG

 

2. On or before the given deadline, auditors must finish and submit their audit works based on the extracted audit data above. Like this:

Audit_Sample_02.PNG

 

3. Once submitted, we, reporting team, must provide column for audit result. But we always do it manually. Until Power BI came up, we need to transform our reports to Power BI. The result of another column showed like this:

Audit_Sample_Result.PNG

 

You may also notice that Audit Result - Amounts may vary and depends on the auditor. Now, for this particular column shown above (Audit Result - Amount in Question), we do have problem creating it due to no idea what DAX or Formula I must use. Kindly help us for this.

 

Should you have any questions, please do let us know.

 

Thanks and stay safe,

Echo

9 REPLIES 9
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

I don't know how your last table is calculated. It shows 1200 for first Audit, but in your table you have 4 lines with 1200, 1200, 1000 and 1200. Is this a MAX-calculation?

 

BR

 

Jimmy

Anonymous
Not applicable

Hi @Jimmy801 ,

 

Good day.

 

I cant say if this is a MAX-Calculation since I dont have any idea. But the amounts indicated there are distinct and might be based on the document submitted. For example:

 

1200 is the total amount of all the BULK receipts. The reason to have 1000 amount in question, might pertain to a one receipt with an amount of 1000 and we need to raise an issue. That is why we showed it in a diffrent row. On the other hand, once we raised, 1200 meaning all of the receipts have same issue only and applied to all. 

 

I hope I answer your question 🙂

 

Thanks and regards

Hello @Anonymous 

 

sorry, I don't get what you want to have calculated in your custom column.

Your data model shows this with values of 1200, 1200 1000 an d1200 in the colum AMOUNT IN QUESTION

image.png

 

Your grouped table shows this

image.png

 

I have to know how this column is grouped/created.

 

BR

 

Jimmy

Anonymous
Not applicable

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 REFERENCEORIGINAL (Y)Customer Name Spend - Expense Amount (USD)  AMOUNT IN QUESTION SPECIFIC
AUDIT ISSUE
Current Audit Status
OrigUniqRef_01 OrigUniqRef_01YCustomer A               1,200.00                1,200.00Expense for ClarificationWith Issue
OrigUniqRef_011OrigUniqRef_01.L1 Customer A               1,200.00                1,200.00Business Purpose Not ProvidedWith Issue
OrigUniqRef_012OrigUniqRef_01.L2 Customer A               1,200.00                1,000.00Only Credit Card Slip/Statement is provided.With Issue
OrigUniqRef_013OrigUniqRef_01.L3 Customer A               1,200.00                1,200.00No Time ChargesWith 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 REFERENCEORIGINAL (Y)Customer Name Spend - Expense Amount (USD)  AMOUNT IN QUESTION SPECIFIC
AUDIT ISSUE
Current Audit Status
OrigUniqRef_02 OrigUniqRef_02YCustomer B               1,500.00                    900.00Receipt not providedWith Issue
OrigUniqRef_021OrigUniqRef_02.L1 Customer B               1,500.00                    900.00Expense for ClarificationWith 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

Anonymous
Not applicable

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

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
Not 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:

Audit_Sample_Result-Power BI 1.PNG

 

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,

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 

Anonymous
Not 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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.