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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Ashish_Mathur
Super User
Super User

Insert 8 blanks rows after each row

Hi,

 

I have a dataset with 21 column and 6 rows.  Using the Query Editor, I would like to insert 8 blank rows after each row.  How can this be done?

 

Thank you.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Ashish_Mathur,

 

Using this post and making some change to the custom function I was abble to achieve the result you need.

 

Check below the revised function with indication of where you need to add fields for empty rows.

 

let
    AddEmptyRows = (Tbl as table, HeadersToGroup as list, groupKind as number) as table =>
    let 
        FirstRecord = Tbl{0},
 
        // create an empty record
        EmptyRecord = 
            let 
                FieldNames = Record.FieldNames(FirstRecord),
                EmptyValues = List.Repeat({""},Record.FieldCount(FirstRecord))
            in
                Record.FromList(EmptyValues,FieldNames),
 
        // group table
        GrpTable = Table.Group(
                        Tbl, 
                        HeadersToGroup, 
                        {"Tbl", each _, type table}, 
                        groupKind ),
       // transform table column of grouped table adding 1 empty row at the bottom
        TransformTblCol = Table.TransformColumns(
                              GrpTable,
                              {"Tbl", each Table.InsertRows(_, Table.RowCount(_), {EmptyRecord , EmptyRecord  , EmptyRecord , EmptyRecord , EmptyRecord ,EmptyRecord ,EmptyRecord ,EmptyRecord   })} 
                                                                    // add EmptyRecord for each additional line you would like
                           ),
        // Select the tbl column and expand it
        ExpandColumns = Table.ExpandTableColumn(
                            Table.SelectColumns(
                                TransformTblCol,
                                {"Tbl"}
                                ),
                        "Tbl",
                        Record.FieldNames(FirstRecord)
                        ),
 
       // build a list containing the header name and the Type of each column of Source 
       ColTypes = List.Accumulate(
                     Record.FieldNames(FirstRecord),
                     {},
                     (state, current) => state & {{current, Value.Type(Record.Field(FirstRecord, current))}}
                  )
 
    in
      Table.TransformColumnTypes(ExpandColumns ,ColTypes)
in
    AddEmptyRows

See also atach PBIX file with example.

 

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @Ashish_Mathur,

 

Using this post and making some change to the custom function I was abble to achieve the result you need.

 

Check below the revised function with indication of where you need to add fields for empty rows.

 

let
    AddEmptyRows = (Tbl as table, HeadersToGroup as list, groupKind as number) as table =>
    let 
        FirstRecord = Tbl{0},
 
        // create an empty record
        EmptyRecord = 
            let 
                FieldNames = Record.FieldNames(FirstRecord),
                EmptyValues = List.Repeat({""},Record.FieldCount(FirstRecord))
            in
                Record.FromList(EmptyValues,FieldNames),
 
        // group table
        GrpTable = Table.Group(
                        Tbl, 
                        HeadersToGroup, 
                        {"Tbl", each _, type table}, 
                        groupKind ),
       // transform table column of grouped table adding 1 empty row at the bottom
        TransformTblCol = Table.TransformColumns(
                              GrpTable,
                              {"Tbl", each Table.InsertRows(_, Table.RowCount(_), {EmptyRecord , EmptyRecord  , EmptyRecord , EmptyRecord , EmptyRecord ,EmptyRecord ,EmptyRecord ,EmptyRecord   })} 
                                                                    // add EmptyRecord for each additional line you would like
                           ),
        // Select the tbl column and expand it
        ExpandColumns = Table.ExpandTableColumn(
                            Table.SelectColumns(
                                TransformTblCol,
                                {"Tbl"}
                                ),
                        "Tbl",
                        Record.FieldNames(FirstRecord)
                        ),
 
       // build a list containing the header name and the Type of each column of Source 
       ColTypes = List.Accumulate(
                     Record.FieldNames(FirstRecord),
                     {},
                     (state, current) => state & {{current, Value.Type(Record.Field(FirstRecord, current))}}
                  )
 
    in
      Table.TransformColumnTypes(ExpandColumns ,ColTypes)
in
    AddEmptyRows

See also atach PBIX file with example.

 

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur, If it works please mark the answer as correct. Regards, MFelix

Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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