How can I create a column in a power query that inserts a formula into table after you close and load the power query?

Cynthia McNeill 0 Reputation points
2025-08-10T17:30:01.9366667+00:00

I would like to create a table from a power query that contains a column "TotQty" and in this column I want it to contain a SUMIFS formula. Here is the actual formula that I would like for the table to contain "=SUMIFS([Qty],[Item ID],[@[Item ID]],[Name],[@Name])." I am wanting the TotQty column to contain this formula after I load from the Power Query.

I cannot seem to make this happen in the power query. In the power query, I have selected to insert a custom column, and I then put the formula that I wanted into the Custom Column Formula section.

I am not allowed to proceed because I am told that I have and invalid identifier.

User's image

I am using MS 365 Apps for Business, Excel version 2507.

If anyone could help me to identify what I am doing wrong I would greatly appreciate it. Thank you!!

Microsoft 365 and Office | Excel | For business | Windows
{count} votes

3 answers

Sort by: Most helpful
  1. riny 19,670 Reputation points Volunteer Moderator
    2025-08-10T18:51:09.1266667+00:00

    Power Query is not Excel. SUMIFS is not a Power Query function. What exactly are you trying to achieve in PQ?

    0 comments No comments

  2. Huy-K 1,860 Reputation points Microsoft External Staff Moderator
    2025-08-11T00:06:40.02+00:00

    Dear @Cynthia McNeill,

    Good day! Thank you for posting your question in the Microsoft Q&A forum.

    We apologize for any inconvenience you may encounter when using our services/ products. Based on your description:

    The error message "Invalid identifier" arises from the way Power Query processes formulas. Unlike Excel, Power Query does not support Excel-style functions such as =SUMIFS(...) within its custom column editor.

    To effectively achieve your objective, consider the following alternative methods:

    After loading the data from Power Query into Excel, you can generate a TotQty column that replicates the behavior of the SUMIFS formula by following the steps outlined below.

    Option 1: Add the Formula in Excel After Load

    1.     Load your Power Query table into Excel.

    2.     In Excel, add a new column next to your table.

    3.     Enter the formula:

    =SUMIFS([Qty],[Item ID],[@[Item ID]],[Name],[@Name])
    

    4.     Excel will automatically fill this formula down the column if your table is formatted as a Table (which Power Query does by default).

    Option 2: Use Power Query Grouping Instead

    If you want to calculate the total quantity per Item ID and Name within Power Query, you can:

    1. Go to Transform Data.
    2. Select both Item ID and Name columns.
    3. Click Group By.
    4. In the dialog:
      • Group by: Item ID and Name
      • New column name: TotQty
      • Operation: Sum
      • Column: Qty
    5. Merge this grouped table back with your original table using a merge query on Item ID and Name.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    User's image

    0 comments No comments

  3. p45cal 0 Reputation points
    2025-08-11T14:02:25.6933333+00:00

    you can also test out a one-liner

    (Source is the previous step name or any step name that has a table with the 3 required columns in (as long as it doesn't cause a circular reference).)

    = Table.AddColumn(Source, "Sum If", each ((ID,Nm)=>List.Sum(Table.SelectRows(Source, each ([Item ID] = ID) and ([Name] = Nm))[Qty]))([Item ID],[Name]))

    The 2 references to Source don't both have to refer to the same step, eg. it would be quite normal to have the likes of:

    = Table.AddColumn(PreviousStep, "Sum If", each ((ID,Nm)=>List.Sum(Table.SelectRows(Source, each ([Item ID] = ID) and ([Name] = Nm))[Qty]))([Item ID],[Name]))

    where PreviousStep is just that and Source could refer to the first step in the query (better too if that Source step includes Table.Buffer in it).

    User's image

    On an Excel sheet it looks like:

    User's image

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.