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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
agd50
Helper V
Helper V

Expanding/Duplicating Rows with the same values?

agd50_0-1679375048108.png I want to be able to duplicate a row only if the value is 2, 3 or more - so that it will duplicate it to this value  (ie 2 = 2 rows). The rest of the row includes workers details. Is this possible?
(sensitive data)

 

2 ACCEPTED SOLUTIONS
Ahmedx
Super User
Super User

= Table.TransformColumns(
from, { "Count", (x)=> 
 List.Transform(List.Repeat( {x},x),(y)=> 1)
}
)


Yes, you can do it in power query For it
watch my video here
https://1drv.ms/v/s!AiUZ0Ws7G26RhkuysN5T04JZpItg?e=UErUKu

View solution in original post

Ahmedx
Super User
Super User

I'm sorry, you can shorten the M code like this

= Table.TransformColumns(
from, { "Count", (x)=> 
 List.Transform(List.Repeat( {x},x),(y)=> 1)
}
)

to

= Table.TransformColumns(
from, { "Count", (x)=> List.Repeat( {"1"},x)
})

View solution in original post

7 REPLIES 7
Ahmedx
Super User
Super User

I'm sorry, you can shorten the M code like this

= Table.TransformColumns(
from, { "Count", (x)=> 
 List.Transform(List.Repeat( {x},x),(y)=> 1)
}
)

to

= Table.TransformColumns(
from, { "Count", (x)=> List.Repeat( {"1"},x)
})

agd50_1-1679447267472.png (Before)

 

agd50_0-1679451791544.png

 (After)

 

 

How would the formula change for any additional columns such as the imaginary one I have added? The logic is if 0 then = 0 (I got Null), IF 1 = 1, Else IF greater than 1 (2 or more) than duplicate the entire row.

Ahmedx
Super User
Super User

= Table.TransformColumns(
from, { "Count", (x)=> 
 List.Transform(List.Repeat( {x},x),(y)=> 1)
}
)


Yes, you can do it in power query For it
watch my video here
https://1drv.ms/v/s!AiUZ0Ws7G26RhkuysN5T04JZpItg?e=UErUKu

You are a champion, I wish i had your brain. I assume that this is M Code?

Well done.

agd50
Helper V
Helper V

agd50_0-1679377450783.pngagd50_1-1679377521903.png

This is effectively what I want to do - (1st is before - 2nd screenshot is after) - Obviously just much more data.

Ahmedx
Super User
Super User

this can be done in power query
make a small example so we can help you

I have created a pbix file but you can't upload that here, would an excel sheet be better?

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

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.