'How to populate rows based on the number required in google sheet?

enter image description here

Hi all,

I want to use a formula to duplicate the department name based on the number of employee in the department. For example. there are 2 employee in Finance department, so the formula will duplicate 2 Finance in column E, and there are 7 employee in Product department, then the formula will duplicate 7 Product in column E below Finance. Column E is the expected output that I want to achieve. Not sure whether it is possible to achieve or not. Any help or advise will be greatly appreciated!



Solution 1:[1]

Try

=ARRAYFORMULA(TRIM(TRANSPOSE(SPLIT(QUERY( REPT(B3:B&"?", C3:C), ,9^9), "?"))))

enter image description here

Solution 2:[2]

use:

=INDEX(FLATTEN(TRIM(SPLIT(QUERY(REPT(B3:B&"?",C3:C),,9^9),"?"))))

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mike Steelson
Solution 2 player0