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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

How to insert a row every 3 rows

Hello, is there a simple way to insert a row every 3 rows?

My use-case is fairly straightforward, I need a repeating row #question_answer as in the sample:

 

#question_answerbregjiewpjgrw
#questionbregjiewpjgrw
#answeranswer1
#question_answercaherjtykukgkh
#questioncaherjtykukgkh
#answeranswer2
#question_answerabdscefefa
#questionabdscefefa
#answeranswer3
Script to insert hereScript to insert here
#questiondwafegbbg
#answeranswer4

 

Ideally, as shown, it would contain plain data (the string #question_answer )in the first column, and a reference to the cell below in the second. 

 

Very grateful for any suggestions

1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following steps to meet your requirement.

  1. Open the Power Query and we need to add a new customer column,
if [Column 1] = "#question"
then {"New","Origin"}
else {"Origin"}
 

 

  1. Then we need to expand the columns to new row,
 

15.jpg

 

  1. Then we can create a replace step and replace with another logical condition.
= Table.ReplaceValue(#"Expanded Temp",each [Column 1],each if [Temp] = "New" then "#question_answer" else  [Column 1],Replacer.ReplaceText,{"Column 1"})
 

16.jpg

 

  1. At last we can delete the Temp column, and get the result like this,
 

17.jpg

If you have any questions, please kindly ask here and we will try to resolve it.

 

All the queries are here:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcs7DoAgEATQu6ytjZ/bGIpFllVIUPmEeHtJaEygm8zM2zYYnkQhnpeDEaQnNifl27DPIMayoguZfNlqmGr7Mzse5E18bbJsjy6aG4RShZ00aeyCpQEqoyaWkrv/FYT4AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Column 1" = _t, #"Column 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column 1", type text}, {"Column 2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Temp", each if [Column 1] = "#question"
then {"New","Origin"}
else {"Origin"}),
    #"Expanded Temp" = Table.ExpandListColumn(#"Added Custom", "Temp"),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Temp",each [Column 1],each if [Temp] = "New" then "#question_answer" else  [Column 1],Replacer.ReplaceText,{"Column 1"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Temp"})
in
    #"Removed Columns"

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-lid-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following steps to meet your requirement.

  1. Open the Power Query and we need to add a new customer column,
if [Column 1] = "#question"
then {"New","Origin"}
else {"Origin"}
 

 

  1. Then we need to expand the columns to new row,
 

15.jpg

 

  1. Then we can create a replace step and replace with another logical condition.
= Table.ReplaceValue(#"Expanded Temp",each [Column 1],each if [Temp] = "New" then "#question_answer" else  [Column 1],Replacer.ReplaceText,{"Column 1"})
 

16.jpg

 

  1. At last we can delete the Temp column, and get the result like this,
 

17.jpg

If you have any questions, please kindly ask here and we will try to resolve it.

 

All the queries are here:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bcs7DoAgEATQu6ytjZ/bGIpFllVIUPmEeHtJaEygm8zM2zYYnkQhnpeDEaQnNifl27DPIMayoguZfNlqmGr7Mzse5E18bbJsjy6aG4RShZ00aeyCpQEqoyaWkrv/FYT4AA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Column 1" = _t, #"Column 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column 1", type text}, {"Column 2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Temp", each if [Column 1] = "#question"
then {"New","Origin"}
else {"Origin"}),
    #"Expanded Temp" = Table.ExpandListColumn(#"Added Custom", "Temp"),
    #"Replaced Value" = Table.ReplaceValue(#"Expanded Temp",each [Column 1],each if [Temp] = "New" then "#question_answer" else  [Column 1],Replacer.ReplaceText,{"Column 1"}),
    #"Removed Columns" = Table.RemoveColumns(#"Replaced Value",{"Temp"})
in
    #"Removed Columns"

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

This works perfectly. Thank you for the detailed writeup, it really helps me understand the method.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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