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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
RobRayborn
Helper IV
Helper IV

Power Query Add rows of zero amount

I have a need to add rows of data of a zero quantity.  I have three columns PART, DATE, QTY.

For each row add one month to the DUE DATE twelve times, so if the original data is Part A, 4/1/2026, 26, then I need to append to it  Part A, 5/1/2026, 0, and Part A, 6/1/2026, 0.... out twelve months.
When I piped this request thought Copilot it came back with:

Add12Months =
Table.TransformColumns(
#"Calculated Start of Month",

"GeneratedRows",
each
List.Transform(
{1..12}, // 12 months ahead
(i) => [
ITEM NUMBER = [ITEM NUMBER],
DUE DATE = Date.AddMonths([DUE DATE], i),
QTY DUE = 0
]
)
),

// Convert the lists into actual rows
ExpandGenerated =
Table.ExpandListColumn(Add12Months, "GeneratedRows")
> Table.ExpandRecordColumn(
_,
"GeneratedRows",
{"ITEM NUMBER", "DUE DATE", "QTY DUE"}
),

// Append original rows + generated future rows
FinalTable = Table.Combine({Source, ExpandGenerated})
in
FinalTable

Though it shows No Syntax errors have been detected in the Advance Editor, when I let the query run I receive this error:
An error occurred in the ‘’ query. Expression.Error: The name '_' wasn't recognized. Make sure it's spelled correctly.

If someone could help me figure out how to get this to work, I would greatly apprecate it. It will solve one of my biggest problems with incoming incomlete data.

 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

Here is a sample code that uses similar logic to your example.

let
    Source = 
    Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText("i45WCkgsKlFwVNJRMtE31DcyMDIDMoFErA5UygnIN0ZImZsrxcYCAA==", BinaryEncoding.Base64), 
                Compression.Deflate
            )
        ), 
        let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Part = _t, Date = _t, Qty = _t]
    ),
    #"Changed Type" = 
    Table.TransformColumnTypes(
        Source,
        {
            {"Part", type text}, {"Date", type date}, {"Qty", Int64.Type}
        }
    ),
    generate_records = 
    Table.AddColumn(
        #"Changed Type", 
        "next12Months", 
        each 
        List.Transform(
            {0..12}, 
            (r)=> [
                Part=[Part], 
                Date=Date.AddMonths([Date], r), 
                Qty=if r = 0 then [Qty] else 0
            ]
        ), 
        type list
    ),
    remove_columns = 
    Table.RemoveColumns(
        generate_records,
        {"Part", "Date", "Qty"}
    ),
    expand_lists = 
    Table.ExpandListColumn(
        remove_columns, 
        "next12Months"
    ),
    expand_records = 
    Table.ExpandRecordColumn(
        expand_lists, 
        "next12Months", 
        {"Part", "Date", "Qty"}, 
        {"Part", "Date", "Qty"}
    ),
    set_types = 
    Table.TransformColumnTypes(
        expand_records,
        {
            {"Part", type text}, {"Date", type date}, {"Qty", Int64.Type}
        }
    )
in
    set_types

Here I start with example table...

jgeddes_0-1774026964370.png

and end with...

jgeddes_1-1774026985692.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
RobRayborn
Helper IV
Helper IV

Thank you so very much. You have helped to solve my issue of missing data.

jgeddes
Super User
Super User

Here is a sample code that uses similar logic to your example.

let
    Source = 
    Table.FromRows(
        Json.Document(
            Binary.Decompress(
                Binary.FromText("i45WCkgsKlFwVNJRMtE31DcyMDIDMoFErA5UygnIN0ZImZsrxcYCAA==", BinaryEncoding.Base64), 
                Compression.Deflate
            )
        ), 
        let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Part = _t, Date = _t, Qty = _t]
    ),
    #"Changed Type" = 
    Table.TransformColumnTypes(
        Source,
        {
            {"Part", type text}, {"Date", type date}, {"Qty", Int64.Type}
        }
    ),
    generate_records = 
    Table.AddColumn(
        #"Changed Type", 
        "next12Months", 
        each 
        List.Transform(
            {0..12}, 
            (r)=> [
                Part=[Part], 
                Date=Date.AddMonths([Date], r), 
                Qty=if r = 0 then [Qty] else 0
            ]
        ), 
        type list
    ),
    remove_columns = 
    Table.RemoveColumns(
        generate_records,
        {"Part", "Date", "Qty"}
    ),
    expand_lists = 
    Table.ExpandListColumn(
        remove_columns, 
        "next12Months"
    ),
    expand_records = 
    Table.ExpandRecordColumn(
        expand_lists, 
        "next12Months", 
        {"Part", "Date", "Qty"}, 
        {"Part", "Date", "Qty"}
    ),
    set_types = 
    Table.TransformColumnTypes(
        expand_records,
        {
            {"Part", type text}, {"Date", type date}, {"Qty", Int64.Type}
        }
    )
in
    set_types

Here I start with example table...

jgeddes_0-1774026964370.png

and end with...

jgeddes_1-1774026985692.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.