Separating "0 yen" from "Unconfirmed amount" in Power Query billing aggregation

VBA・Officeカテゴリを表すパンダのイラスト VBA / Office

About this article
This article was created using an automated generation workflow leveraging generative AI. It demonstrates a method for aggregating a dummy billing list without deleting rows that cannot be converted.

Verification Status: 📘 Cross-checked against the official Power Query M specifications. Query execution and sheet loading in Excel have not been verified. Table numbers represent expected results.

Supported Environments, Capabilities, and Limitations (Verified: December 6, 2026 JST)

ItemTarget / Condition
TargetEnvironment using Windows desktop Excel where Power Query blank queries and the Advanced Editor can be accessed
CapabilitiesRead 4 dummy billing details using a query and split them into confirmed, pending review, and provisional aggregation
Limitations & Unverified ItemsNo original client document verification or payment approval is performed. Mac and Web UI compatibility, operation feasibility, and physical device execution of this code are unverified.
Safety PrecautionsUse only dummy data in a new workbook

You are tasked with aggregating a list of 4 billings by the beginning of next week. The amounts are listed as "12000", "Unconfirmed", "8500", and "0". If you treat "Unconfirmed" as 0 yen simply because it could not be converted, it will become indistinguishable from actual 0 yen values in the aggregation. As a result, you will lose track of whom to ask for the correct amount.Total 20,500 yen, with 1 unconfirmed item.Returning both of these simultaneously is what this Power Query achieves.

ItemScope of this example
Testing environmentDesktop version of Excel that can open the Power Query Advanced Editor
DataPractice text strings only. No connection to files or external services
Amount conventionsIntegers greater than or equal to 0. Single-byte numbers only, up to 9 digits. Decimals, commas, currency symbols, and negative numbers require verification
ResultsConfirm finalized details, unfinalized details, and aggregations separately

Split the four items into those for reporting and those for inquiry

Suppose this list is handed over to accounting at the end of the month. The aggregation team only needs the total of the details whose amounts could be verified. The inquiry team needs the unfinalized list with reasons and detail IDs attached. Information for two different tasks can be generated from a single list without altering the original amount column.

Detail IDOriginal AmountNumeric AmountStatus
INV-011200012000Finalized
INV-02UnverifiedBlankRequires verification
INV-0385008500Confirmed
INV-0400Confirmed

For INV-02, whose original input is "Unverified", there is no verifiable amount, so the numeric field is left blank. Meanwhile, the "0" for INV-04 is a figure based on an agreement. This is included in the confirmed items as a numerical 0. Whether an amount is confirmed is determined independently of how many yen are added to the total.

flowchart TD
A["受け取った4件"] --> B["金額を判定"]
B --> C["確定3件"]
B --> D["要確認1件"]
C --> E["報告は20500円"]
D --> F["照会する明細はINV-02"]

Try with a blank query

In a new workbook in Excel for Windows, select "Data" -> "Get Data" -> "From Other Sources" -> "Blank Query". After opening the Power Query Editor, paste the following code into the "Advanced Editor". The code only uses the four dummy line items written at the beginning. You do not need to open the actual invoice file.

let
    Source = #table(
        type table [明細ID = text, 元金額 = nullable text],
        {
            {"INV-01", "12000"}, {"INV-02", "未確認"},
            {"INV-03", "8500"}, {"INV-04", "0"}
        }
    ),
    Digits = {"0".."9"},
    Classify = (raw as nullable text) as record =>
        let
            t = if raw = null then "" else Text.Trim(raw)
        in
            if t = "" then
                [数値金額 = null, 理由 = "金額の記入なし"]
            else if Text.Length(t) > 9 or Text.Select(t, Digits) <> t then
                [数値金額 = null, 理由 = "半角整数9桁以下の取り決め外"]
            else
                let parsed = try Number.FromText(t, "ja-JP")
                in if parsed[HasError] then
                    [数値金額 = null, 理由 = "金額の変換に失敗"]
                else
                    [数値金額 = parsed[Value], 理由 = null],
    Judged = Table.AddColumn(Source, "点検", each Classify([元金額]), type record),
    Result = Table.ExpandRecordColumn(Judged, "点検", {"数値金額", "理由"}),
    Accepted = Table.SelectRows(Result, each [理由] = null),
    Review = Table.SelectRows(Result, each [理由] <> null),
    ValidCount = Table.RowCount(Accepted),
    Summary = #table(
        type table [確定件数 = number, 要確認件数 = number, 確定分合計 = nullable number],
        {{ValidCount, Table.RowCount(Review),
          if ValidCount = 0 then null else List.Sum(Accepted[数値金額])}}
    )
in
    [確定明細 = Accepted, 要確認明細 = Review, 集計 = Summary]

The "Record" at the top of the results is a container that allows you to look up three items by name: "Confirmed items", "Items requiring verification", and "Summary". The three items are lined up in the Power Query Editor preview. Open the value displayed in Table for the item you want to view. To return to the original three items, select the step prior to opening the next table under "Applied Steps" in the practice query. Check the "Summary" to confirm 3 confirmed items, 1 item requiring verification, and a confirmed total of 20,500 yen. Next, view INV-02 under "Items requiring verification". The expectation is that both the original text "Unverified" and the reason for deviating from the agreement are retained. "Confirmed items" includes the 0 for INV-04. Rather than just looking at whether a cell is blank, checking which item list it ended up in makes it easier to verify the sorting.

Determine the accepted format before checking if the code can be converted to a number

First, remove leading and trailing whitespace. If nothing remains, it is "Amount not entered". Next, check if it consists solely of single-byte digits and is 9 digits or less. If it does not meet this rule, do not convert it to a number and instead retain the original text. "12,000" is readable to humans, but here it requires verification. The 9-digit upper limit is a rule for this tutorial and is not a common rule for actual invoicing.

Convert only those items that match the rules to numbers using Number.FromText.try is a pattern to return results without stopping the entire process if a conversion fails there.HasError logs the reason if it indicates a failure. It reads Value only upon success, thereby avoiding extracting values from failed results. Finally, rows without a reason are classified into confirmed line items, and rows with a reason into line items requiring review.

You should not indiscriminately delete non-numeric characters upon import. For instance, even if a convention of using commas is introduced, correcting "1,200" to the same value as "12,00" with a misaligned digit is a different issue. First, determine the source of transfer, thousand separators, decimal points, and currency units. Place one valid example and one invalid example in a practice table, and incorporate them into your workflow only after you are able to distinguish between both.

Modify only INV-02 and observe how the item count changes even if the total remains the same

Modify only INV-02 in the practice data and leave the other three items as they are. If you confirm the original document shows 0 yen, set it to "0". If the input character was simply deleted, leave it blank. Although all of the following three have a total of 20,500 yen, whether reconciliation work remains differs.

INV-02 inputTotal for confirmed itemsConfirmed / Requires ReviewNext task
Unverified20,500 yen3 / 1Inquire about the basis for the billing
020,500 yen4 / 0Verify if there is a basis for 0 yen
Blank20,500 yen3 / 1Cross-check missing items with the source data
flowchart TD
A["合計が前回と同じ"] --> B{"要確認は何件か"}
B -->|1件| C["元資料を照会する"]
B -->|0件| D["変更した入力の根拠を見る"]
D --> E["根拠があれば締め判断へ"]

Also check whether the sum of the confirmed count and the pending verification count matches the original 4 items. If they do not match, verify the imported data before correcting the amounts. If a row was not imported, re-entering the correct amount will not restore the count. Conversely, if the counts match, next check which line item INV-02 belongs to. Narrowing down the scope to check makes it easier to find compared to returning directly to the source data.

As another check, try leaving 12000, 8500, and 0 all blank. If INV-02 remains "Unverified", the confirmed count is 0 and the total is null. This indicates "No confirmed items". If there is one or more confirmed line items and the summed amount is 0 yen, output a numeric 0. To prevent blank cells from being misinterpreted as 0 yen, display the confirmed count alongside the total in the report.

Handing over as a provisional value until the inquiry is complete

Write "Confirmed: 20,500 yen, Pending verification: 1 item" in the report to communicate that the total does not cover all items. Provide the inquiry team with line item IDs like INV-02 and the specific points to verify. There is no need to attach the entire invoice to the email. Only authorized personnel should check the actual physical documents in the approved storage location.

flowchart TD
A["照会先から回答"] --> B{"元資料で値を確認できたか"}
B -->|いいえ| C["未確定のまま残す"]
B -->|はい| D["入力元を訂正"]
D --> E["再集計し件数と明細を照合"]

Once the values are confirmed through the inquiry, correct the data source and refresh the query. Manually typing 0 into the output table alone will revert upon refresh, and the basis for that 0 will remain untraceable. After re-importing, check whether only the queried ID has moved from pending verification to confirmed. Even if the total does not change, the audit trail indicating that "1 pending item moved to confirmed" is preserved.

When the recipient of the report cross-checks the following three items, it prevents amounts from being utilized prematurely. First, verify which date's list was aggregated. Second, verify whether the 4 received items are split into 3 confirmed items and 1 pending item. Third, verify whether the title clearly indicates that 20,500 yen is solely the confirmed amount. If a 5th item arrives after receipt, do not directly edit the previous table; instead, re-import using the new list and rewrite the date and item count. Do not apply the same "No issues" mark to a table where pending items have become 0 or to a blank table for a day when no list was received in the first place. Verify whether the received item count should be 0 before utilizing the numbers.

If the inquiry is not completed by the cutoff date and time, the on-site management personnel decide whether to wait for the cutoff, issue a provisional report for the confirmed portion only, and pursue the rest separately. Power Query checks the input structure and transformation results. It is not a function for cross-checking against invoices or approving payments. Clearly state this boundary in a single sentence to the recipients of the summary table.

GitHub sample

Fixed version of learning materials and execution proceduresPlease refer to.

Reference materials

Glossary

  • Power Query: A feature in Excel and other applications that imports data and formats it according to predefined steps.

  • Query: A saved procedure that specifies which data to read and the sequence for formatting it.

  • null: In this context, a value indicating the absence of a numerical value. It does not represent a value of zero.

  • Provisional aggregation: A figure calculated using only the finalized range while leaving unconfirmed items pending.

Document information

Article title
Separating "0 yen" from "Unconfirmed amount" in Power Query billing aggregation
Published
Updated
Source
https://papanda925.com/?p=19238&lang=en

License: Text and original figures for which this site holds the relevant rights are available under CC BY 4.0 , unless otherwise noted. This article may include content created or edited with generative AI. If code has a separate license notice or a linked GitHub repository license, that license takes precedence for the code. Quotations, third-party materials, images, and trademarks are excluded from this license. Usage policy

Copied title and URL