+ Reply to Thread
Results 1 to 27 of 27

Dividing rows into deciles

  1. #1
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Dividing rows into deciles

    Hey,

    I'm trying to divide each row in my file into deciles. To be more precise, I have the stocks of an index sorted according their past volatility and want to create 10 equally large portfolios for every month (see attachment). So for example if I have 100 stocks in a month, I want 10 portfolios with 10 stocks in each of the portfolio. But next month it could be that there are 120 stocks sorted, so every portfolio would have 12 stocks. Does anybody know a command or a methode to divide a row into deciles? So that in decile 1 are the first 10% of the stocks, in decile 2 the second 10% of the stocks etc. I would really appreciate an answer, since I don't know how to move on.

    Thank you very much!

    Edit: I have attached an excel file of an example

    My goal is to calculate the average of the first decile cells in a row, than the average of next decile of cells etc.

    In my example there are exactly 100 cells so each decile would be exactly 10 cells. But it changes in every row, sometimes there are 150 cells, sometimes 136 cells etc.
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by lorenzo2207; 07-26-2022 at 06:14 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Dividing rows into deciles

    Welcome to the forum.

    There are instructions at the top of the page explaining how to attach your sample workbook.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Unhappy Re: Dividing rows into deciles

    Does anybody have a clue, please?
    I still can't figure it out

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Dividing rows into deciles

    You didn't tell us you'd added the workbook - no way of knowing unless you tell us!

    I will have a look.

  5. #5
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Dividing rows into deciles

    In B7 then drag accross:
    Please Login or Register  to view this content.
    Quang PT

  6. #6
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Thank you for your answer! The formula works for that specific row. But how would do it, if in the next row there are 120 numbers instead of 100, in the next row 123 numbers etc. The number of cells change in every row.
    Last edited by lorenzo2207; 07-27-2022 at 05:25 AM.

  7. #7
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    I attached another workbook to show what I mean. The number of cells in a row change in every row and I want the average from every decile in every row.
    Attached Files Attached Files

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    Try

    =IF(B6="","",AVERAGE(OFFSET($B$3:$K$3,,COUNTA($B$6:B$6)*(COUNTA($3:$3)/10)-(COUNTA($3:$3)/10),,INT(COUNTA($3:$3)/COUNTA($6:$6)))))

    What result do you want with 156 entries? above gives deciles of 15.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  9. #9
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Thank you for the answer John!
    Could you maybe show me how the formula works on the work book one message before? Can I then just drag the formula down for all rows? For 156 etries it should just divide all the numbers, so four deciles would have 15 entries and six deciles would have 16 entries, in total 156. It should represent stock returns that are divided in 10 equally large portfolios every month, where every row is a separate month.

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    Based on your posted file:

    in B46

    =IF(B6="","",AVERAGE(OFFSET($B4:$XFD4,,COUNTA($B$45:B$45)*INT((COUNTA($4:$4)/10+1))-INT(COUNTA($4:$4)/10+1),,INT(COUNTA($4:$4)/COUNTA($45:$45))+1)))

    Copy across and down

    Just seen your reply so dividing deciles as you described (15s and 16s) will probably require VBA: I certainly don't know how to do it with a formula
    Last edited by JohnTopley; 07-27-2022 at 05:53 AM.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Dividing rows into deciles

    For future reference, if you have multiple rows with a requirement such as you have now described, then there needs to be more than ONE row in the sample workbook for your helpers to see. Try to give us ALL of the information needed at the outset: don't assume that your helper will fill the gaps, because they don't and can't possibly know what's not there.

  12. #12
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Alright no problem John, but thank you very much for the response anyway! I guess I will just simply do it manually then for every row. It will take me a while, but eventually it's done lol

  13. #13
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Quote Originally Posted by AliGW View Post
    For future reference, ...
    I'm really sorry, its my first post here and didn't want to confuse anyone by posting a ton of data. But of course you are right, a few more rows would have been helpful for you.
    Last edited by AliGW; 07-27-2022 at 06:07 AM. Reason: Please DON'T quote unnecessarily!

  14. #14
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Dividing rows into deciles

    That's why I am advising you.

  15. #15
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Thank you!

  16. #16
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,869

    Re: Dividing rows into deciles

    Glad to have helped.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

  17. #17
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    Please Login or Register  to view this content.
    I had to "clear contents" on data INPUTt to get correct column count (column A of INPUT)
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Omg John thank you so so much!! You literally saved my day, I was trying to solve this for the past 1.5 days! Wow I'm so happy, thank you so much John!

  19. #19
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    Glad to have helped.

  20. #20
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Dear John,

    I'm sorry that I have to ask for your help again. I tried to run the code again today for another data set and I got an error.
    I just simply switched the input data to another data set. Do you perhaps know how to fix this issue? Thank you very much!

    Sincerely
    Lorenzo
    Attached Files Attached Files

  21. #21
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    See attached.

    The "problem" is the calculation of the nmber of columns in column A which counts the number of non-blank cells.

    It appears that some cells have "data" although they appear blank so I did "Clear Contents" following the last number
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Thank you so so much John, I really appreciate it!!

    Sincerely
    Lorenzo

  23. #23
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Dear John,

    Could I please ask for your help one last time?

    I attached a file with the input data and a example output that I want to create. Its not the whole data set, because it would be to large to upload. Basically I want to split each 2 rows into
    10 more or less (a decile) equally large parts. In the third row (highlighted yellow) it should calculate the formula that I typed in,
    which switches for every decile. I would be really really grateful if you could help me with the splitting of the decile portfolios
    and only if possible, the yellow highlighted row. I know I'm asking for a lot and I'm really sorry, but I just don't how to solve this.

    Sincerely
    Lorenzo
    Attached Files Attached Files

  24. #24
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    Please Login or Register  to view this content.
    Last edited by JohnTopley; 07-29-2022 at 03:01 PM.

  25. #25
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Dear John,
    Thank you very much for your quick response! I tried to run the code in the vba editor, but I'm having troubles getting the right results. I copied the code into the vba editor and then tried to run it in the input sheet, but I dont get any results. Would it be possible to send me the macro in the excel file where I could copy my data in, like in the files before? I would really appreciate it!

    Thank you a lot for your effort!

    Best regards
    Lorenzo

  26. #26
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,206

    Re: Dividing rows into deciles

    See the attached
    Attached Files Attached Files

  27. #27
    Registered User
    Join Date
    07-26-2022
    Location
    Zurich
    MS-Off Ver
    Microsoft 365
    Posts
    14

    Re: Dividing rows into deciles

    Thank you so much John, you are an absolute legend! Thank you thousand times!! I'm really happy!!!!

    Best regards
    Lorenzo

+ 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. Grouping by weighted deciles.
    By gy18par in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-05-2019, 05:45 AM
  2. [SOLVED] How to Create Deciles?
    By arasan25 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-08-2014, 03:55 AM
  3. [SOLVED] Sorting Large amounts of data into deciles/centiles
    By PatrickDC in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-12-2013, 03:52 AM
  4. Calculating Deciles
    By nander in forum Excel General
    Replies: 4
    Last Post: 10-29-2010, 10:25 AM
  5. Divide population into deciles
    By tod11 in forum Excel General
    Replies: 2
    Last Post: 06-17-2009, 12:41 PM
  6. Sumproduct and dividing with blank rows
    By Flashart in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-09-2009, 06:28 PM
  7. How do I simply output Deciles in Excel?
    By iceman30 in forum Excel General
    Replies: 1
    Last Post: 09-26-2005, 02: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