Forum Discussion

agd50's avatar
agd50
Helper V
3 years ago
Solved

Expanding/Duplicating Rows with the same values?

 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)

 

  • 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)
    })

7 Replies

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

    • agd50's avatar
      agd50
      Helper V

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

    • agd50's avatar
      agd50
      Helper V

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

      Well done.

  • 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's avatar
      agd50
      Helper V

       (Before)

       

       (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.

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