+ Reply to Thread
Results 1 to 7 of 7

Repeat the number according to its frequencies

  1. #1
    Registered User
    Join Date
    04-11-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    46

    Repeat the number according to its frequencies

    Hi All

    I have a data like this:

    Number Frequency
    2 1
    12 3
    33 2
    55 4
    56 2
    75 1

    and I want my data according to this:
    2
    12
    12
    12
    33
    33
    55
    55
    55
    55
    56
    56
    75

    i.e. i want my values to repeat themselves according to their frequencies?. Any possible way I can do this?

    Thanks

  2. #2
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Repeat the number according to its frequencies

    Assuming your data is in A1:B7 (headers in row 1) the simplest way is to use a helper column with this formula in C2 copied down

    =SUM(B$1:B1)

    and then in E2 copied down use this formula

    =IF(ROWS(E$2:E2)>SUM(B:B),"",LOOKUP(ROWS(E$2:E2)-1,C$2:C$7,A$2:A$7))

    when you run out of values you get blanks
    Audere est facere

  3. #3
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Repeat the number according to its frequencies

    Hi,

    Assuming that the original data table as you give it is in the range A1:B7 (with headers in row 1), enter this array formula (confirm with CTRL+SHIFT+ENTER, not just ENTER) in your first cell and copy down as required:

    =IFERROR(INDEX($A$2:$A$7,MATCH(TRUE,MMULT((--(ROW($A$2:$A$7)>=TRANSPOSE(ROW($A$2:$A$7)))),$B$2:$B$7)>=ROWS($1:1),0)),"")

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: Repeat the number according to its frequencies

    Nice formula XOR LX!

    another option to do this without a helper column is to use this non-array version

    =IF(ROWS(E$2:E2)>SUM(B:B),"",LOOKUP(ROWS(E$2:E2)-1,SUBTOTAL(9,OFFSET(B$1,0,0,ROW(INDIRECT("1:"&COUNT(B:B))))),A$2:A$7))

  5. #5
    Registered User
    Join Date
    04-11-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: Repeat the number according to its frequencies

    Great!! Thanks a lot everyone. It worked.

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: Repeat the number according to its frequencies

    @daddylonglegs

    Thanks! And likewise!

    An interesting (and new on me) non-array construction. LOOKUP has some nice and unusual applications - I would invariably use a MATCH(TRUE,SUBTOTAL...etc. array formula if I was going this way, though I shall add this one to my collection now!

  7. #7
    Valued Forum Contributor
    Join Date
    10-29-2012
    Location
    Mojokerto,Indonesia
    MS-Off Ver
    Excel 2007
    Posts
    554

    Re: Repeat the number according to its frequencies

    ie table at A1:B7 target at column C
    start target at C1 , fill it manually with =A1
    then start formula at C2 depend on C1

    =IF(COUNTIF(C$1:C1,C1)<INDEX($B$1:$B$6,MATCH(C1,$A$1:$A$6,0)),C1,INDEX($A$1:$A$6,MATCH(C1,$A$1:$A$6,0)+1))

    copy down

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to repeat the same number for 'N" number of times in excel sheet
    By tulasiram in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-12-2013, 03:06 AM
  2. Challe:Trying to copy a range of costs over a number of years but at different frequencies
    By JamesGoulding85 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-31-2013, 02:28 PM
  3. Replies: 2
    Last Post: 05-31-2013, 12:52 PM
  4. Need a macro to repeat a number from one row to the next row
    By peesh567 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2013, 10:42 AM
  5. how to count the number of text frequencies and copy to other cell
    By DG in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-06-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1