+ Reply to Thread
Results 1 to 57 of 57

Formula to convert 1 column/row to matrix

  1. #1
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Formula to convert 1 column/row to matrix

    Hi Everyone
    First of all, I'm come from Vietnam so I'm sorry for my bad English.
    I dont know how to describe the question more clealy so please see the attached file for details.
    Any help would be appreciated.
    Attached Files Attached Files
    Last edited by congnt92; 08-25-2018 at 12:38 PM. Reason: Re-upload

  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,888

    Re: Formula to convert 1 column/row to matrix

    Welcome to the forum!

    Your two arrays look identical to me, so I have no idea what you are trying to do.

    Will you please attach a sample Excel workbook? We are not able to work with or manipulate a picture of one and nobody wants to have to recreate your data from scratch.

    1. Make sure that your sample data are REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired results are also shown (mock up the results manually).

    3. Make sure that all confidential data is removed or replaced with dummy data first (e.g. names, addresses, E-mails, etc.).

    4. Try to avoid using merged cells as they cause lots of problems.

    Unfortunately the attachment icon doesn't work at the moment, so to attach an Excel file you have to do the following: just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.

    Please pay particular attention to point 2 (above): without an idea of your intended outcomes, it is often very difficult to offer appropriate advice.
    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
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    My mind reading device is saying

    =INDEX($1:$1,ROW(A1)) to convert a row to a column or

    =INDEX($A:$A,COLUMN(A1)) to covert a column to a row.

    Mind reading device does need new batteries though not quite sure how you intend to get a matrix from a single row or column

  4. #4
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi AliGW,
    Thank for your quick reply.
    Please see the attached document
    Many tks.
    Attached Files Attached Files

  5. #5
    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,888

    Re: Formula to convert 1 column/row to matrix

    So this is homework?

    Nothing is more frustrating than to be working on homework and to get stuck. Without guidance, you might have no hope of finishing the assignment before the deadline. The Internet can be a big help in that respect, but without learning how to get the right answer, asking others to solve your homework questions for you simply becomes a downward spiral (and it's cheating).

    We do not want to contribute to you cheating yourself out of your education, but we also acknowledge that seeking assistance to learn a concept is a legitimate request.

    If you are genuinely interested in receiving help in the form of tutoring or coaching, then please rephrase the title of your original post to clearly indicate you are seeking coaching or tutoring help. Any forum members (who are willing to assist as a tutor) will modify their responses accordingly to facilitate your learning. Tutors don't tell you the answers, they help you figure it out for yourself; so don't expect answers, expect suggestions, or just plain hints. Also, be specific in describing the function/formula or technique you trying to learn, and tell us what you have attempted so far. Otherwise, expect your plea for homework answers to be ignored.

  6. #6
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by jason.b75 View Post
    My mind reading device is saying

    =INDEX($1:$1,ROW(A1)) to convert a row to a column or

    =INDEX($A:$A,COLUMN(A1)) to covert a column to a row.

    Mind reading device does need new batteries though not quite sure how you intend to get a matrix from a single row or column
    Hi Jason,
    Thank you for your time.
    The "real goal" is in attachment file (post #4)
    I'm sorry for ambiguity question in #1.

  7. #7
    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,888

    Re: Formula to convert 1 column/row to matrix

    See post #5.

  8. #8
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi AliGW
    Because of it is homework then I tried my best to get the answer by myself.
    The original question is get the smallest value of sum start-end point of each code.
    I have idea fr it but I just cannot find the solution how can I convert an array such as
    {-2.8;0;0;0;-17.8;-2.5;0;0;0;0;-15.9;0} (1 row)
    to {-2.8,-17.8;-2.5,-15.9} (2R x 2C)
    Since I'm new with array formula then I start from here.
    Hope you can give me some hints.
    Tks.
    Last edited by AliGW; 08-25-2018 at 12:36 PM.

  9. #9
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    If you're trying to transpose the data so that, for example, all B210 values are in the first row of the array, all B211 values in the second row, etc. Then you need to step back and look at it differently.

    That would only work if the result would be an eqaul number of columns for every row, meaning that you would need to have the same number of every code in your data source. In your sample, you have 5 of the first code and 6 of the second, so the theory fails before you begin.

    Is the data sorted by code, or is it permissable to do so? Match functions love sorted data

    @Ali. I just solved it using the {1} method that we were discussing last week. Do you have any alternative thoughts?
    Last edited by jason.b75; 08-25-2018 at 12:38 PM.

  10. #10
    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,888

    Re: Formula to convert 1 column/row to matrix

    I'm afraid not at the moment. I'm not really quite getting what the OP is after. And I'm just about to go offline for the evening.

    I'll be interested to see how this has developed when I look in again in the morning.

  11. #11
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    For what it's worth, the 'solution' could be very much excel version related. I'm thinking of one thing that should work, but I don't have the correct version of excel to test it.

  12. #12
    Forum Contributor
    Join Date
    10-30-2003
    Location
    Singapore
    MS-Off Ver
    Excel 2019
    Posts
    197

    Re: Formula to convert 1 column/row to matrix

    Post deleted
    Last edited by Bosco; 08-25-2018 at 02:07 PM. Reason: Homework as per notice

  13. #13
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Bosco, please delete your reply, then read post #5.

  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,888

    Re: Formula to convert 1 column/row to matrix

    For the benefit of others:

    Excel 2016 (Windows) 32 bit
    A
    B
    C
    D
    E
    F
    1
    Code Value Hi everyone. I'm so sorry for my bad English.
    2
    B210
    -2.8
    0
    I have a homework about using just 1 array formula sum 2 values of start and end-point then compare them to get smallest value
    3
    B210
    9.9
    B210 starts at row 2, ends at row 6.
    4
    B210
    -5.7
    B210 starts at row 7, ends at row 12.
    5
    B210
    -13.6
    I have to sum value at B2 with B6, sum value at B7 with B12 and then compare them to get smaller value
    6
    B210
    -17.8
    I mean
    7
    B211
    -2.5
    (-2.8) + (-17.8) = (-20.6)
    8
    B211
    7.9
    compare with
    9
    B211
    7.9
    (-2.5) + (-15.9) = (-18.4)
    10
    B211
    -4.7
    So min(-20.6,-18.4) is -20.6
    11
    B211
    -12.3
    The real data is very large, not just B210 and B211. Maybe B212, B213 … and so on. So I need a generic formula for it.
    12
    B211
    -15.9
    13
    My idea is get values like this (array formula in C2)
    14
    {-2.8;0;0;0;-17.8;-2.5;0;0;0;0;-15.9;0}
    15
    Then by some how we have
    16
    {-2.8,-17.8;-2.5,-15.9}
    17
    Finally we using mmult and min like this
    18
    MIN(MMULT({-2.8,-17.8;-2.5,-15.9},{1;1}))
    19
    result is -20.6
    Sheet: Sheet1

  15. #15
    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,888

    Re: Formula to convert 1 column/row to matrix

    So, to summarise:

    1. You want to take the first and last entries for each code number and add them together.
    2. Then you want to find the minimum of all these numbers.

    You are correct that your final MMULT formula gives the correct answer.

  16. #16
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Jason,
    About match formula I tried
    MATCH(value,range,{1,2})
    but no luck.

    Hi AliGW
    Yes you're right.
    My idea is some how I can convert a vector with 1 row to 2R x 2C and then I can using MIN + MMULT to do the rest.
    I'm getting stuck at find a technique to do that.

  17. #17
    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,888

    Re: Formula to convert 1 column/row to matrix

    Yes - I understand. Thanks for clarifying.

    When you say this is homework, what is the level of the course you are undertaking?

  18. #18
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    What did you use to get the array that you show in F14 of your sample file?

    I see evidence of the use of FREQUENCY, but would like to see your actual method.

  19. #19
    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,888

    Re: Formula to convert 1 column/row to matrix

    Jason - I think it's this one in C2 (array entered):

    =IFERROR(($B$2:$B$12)/(($A$2:$A$12<>$A$3:$A$13)<>($A$2:$A$12<>$A$1:$A$12)),0)

    If you evaluate, you should see the array generated.

  20. #20
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi AliGW
    Actually, my teacher is retired Office informatics teacher in an university. He open a "mini course" (at his home) for someone that want to study Excel array formula.
    In class, we will tell the ideas to solve an exercise and then discuss which idea is the best and how to do it with array formula.
    This homework is one of them. So it's difficult to tell the level of this course.

  21. #21
    Forum Expert avk's Avatar
    Join Date
    07-12-2007
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    3,223

    Re: Formula to convert 1 column/row to matrix

    This is your actual data. As per your file you only add code / value only.
    Actually if your data with some logical, its make the difference. i.e. Invoice-Number, Invoice-Date, Code, Nam, Value. or some more.


    atul


    If my answer (or that of other members) has helped you, please say "Thanks" by clicking the Add Reputation button at the foot of one of their posts.

    Also: if your problem is solved, please take the time to mark your thread as SOLVED by going to the top of your first post, selecting "Thread Tools" and then "Mark thread as solved".

  22. #22
    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,888

    Re: Formula to convert 1 column/row to matrix

    In class, we will tell the ideas to solve an exercise and then discuss which idea is the best and how to do it with array formula.
    Ah! So your teacher doesn't know how to do it yet, either? Well, that makes sense.

    I think the way forward is to discuss it here, too.

    This is your actual data. As per your file you only add code / value only.
    Given what the OP has just told us, i.e. this is all theoretical/exploratory, I think we have to assume that he has given us enough relevant information.

  23. #23
    Forum Expert avk's Avatar
    Join Date
    07-12-2007
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    3,223

    Re: Formula to convert 1 column/row to matrix

    For Post #20 "Congnt92.
    As my thinking, you want sum first & last value of particular code.
    In this case you create add one more column for example "Date".
    Secondly, you pull of unique code in another column. Then start & end date & applying sum formula with criteria.
    Between sum range you can pull out Min.
    For more clarity refer attach file.
    Attached Files Attached Files

  24. #24
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi AliGW
    My teacher will give us the answer in the next week.
    In the next week, I and other student will describe our methods and how to do it with formula.
    I have an idea as in the attached file but getting stuck before end it with MMULT :D

    Hi avk,
    This is my actual data. It is just an exercise, nothing more.
    To be more clearly what this course does, I attach another exercise that we solved in last week.
    Tks.
    Attached Files Attached Files

  25. #25
    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,888

    Re: Formula to convert 1 column/row to matrix

    AVK - that makes the problem very easy to solve, however I really believe the challenge is to do it without helper columns. The OP has specifically stated this in post #20:

    ... how to do it with array formula.
    I think we need to stick to that brief.

  26. #26
    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,888

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by congnt92 View Post
    My teacher will give us the answer in the next week.
    When he does, please post it here for those who have been trying to help you.

  27. #27
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Thanks, Ali! I missed that formula! Too busy looking at ways to make it more complicated than I needed too

    There was a mistake in your formula which was not helping your progress, this was producing the final 0 at the end of the array which should not have been there.

    =IFERROR(($B$2:$B$12)/(($A$2:$A$12<>$A$3:$A$13)<>($A$2:$A$12<>$A$1:$A$12)),0)

    The final array is one row more than the others, what you should have done is adjusted both the first and last row in the range to keep the cell count equal to the rest, the same as you did with $A$3:$A$13

    Then if you enclose the whole formula in MIN() I think it should be as simple as adjusting the mathematical operations to get the desired result.

  28. #28
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by avk View Post
    For Post #20 "Congnt92.
    As my thinking, you want sum first & last value of particular code.
    In this case you create add one more column for example "Date".
    Secondly, you pull of unique code in another column. Then start & end date & applying sum formula with criteria.
    Between sum range you can pull out Min.
    For more clarity refer attach file.
    Thank you for your help, avk.
    But we must to solve it without using helper column.


    Quote Originally Posted by AliGW View Post
    When he does, please post it here for those who have been trying to help you.
    Sure, AliGW.
    I will post the answer when him solve it in our class.

  29. #29
    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,888

    Re: Formula to convert 1 column/row to matrix

    Thanks.

  30. #30
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Jason.
    It is my mistake.
    The formula must be
    IFERROR(($B$2:$B$12)/(($A$2:$A$12<>$A$3:$A$13)<>($A$2:$A$12<>$A$1:$A$11)),0)
    Tks.
    Last edited by AliGW; 08-26-2018 at 08:34 AM.

  31. #31
    Forum Contributor
    Join Date
    10-30-2003
    Location
    Singapore
    MS-Off Ver
    Excel 2019
    Posts
    197

    Re: Formula to convert 1 column/row to matrix

    Or...................

    Try this single formula without helper

    In C2, enter :

    =MIN(SUM(INDEX(B2:B12,N(IF(1,AGGREGATE({15,14},6,ROW(A2:A12)-ROW(A1)/(A2:A12="B210"),1))))),SUM(INDEX(B2:B12,N(IF(1,AGGREGATE({15,14},6,ROW(A2:A12)-ROW(A1)/(A2:A12="B211"),1))))))

    The result is -20.6

    Regards
    Bosco

  32. #32
    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,888

    Re: Formula to convert 1 column/row to matrix

    Bosco - this requires each of the code sections to be defined. The idea is not to have to do this. The OP wants a formula that will work with any size of dataset with any number of code sections.

    Please read through post #14 to understand what is required.
    Last edited by AliGW; 08-26-2018 at 10:11 AM.

  33. #33
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Found a way to get your 2 column array, but there is still work to do.

    First you need to split your existing formula into 2 parts. 1 that returns the first value for each code, another that returns the last.

    Nest each or those arrays into CHOOSE with a {1,2} index number.

    The downside is that the zero's returned by IFERROR are still populated in the array, if you can find a way to omit them then you should be able to do what you want, although I think it will result in a very long and complex formula.

    I've done it using a different approach, with 5 functions nested inside the first array of MMULT without transposing.

    I generated the array, 2 columns, 1 row, with unconventional use of VLOOKUP. There is a thread started by Ali, about a week ago, where this unconventional method was suggested and discussed. If you can find it then it might give you some ideas.

  34. #34
    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,888

    Re: Formula to convert 1 column/row to matrix

    The thread to which Jason refers is here: https://www.excelforum.com/excel-for...n-the-fly.html

  35. #35
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Thanks, Ali! I had a look at my post history but couldn't see it, think I unsubscribed in error.

  36. #36
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by Bosco View Post
    =MIN(SUM(INDEX(B2:B12,N(IF(1,AGGREGATE({15,14},6,ROW(A2:A12)-ROW(A1)/(A2:A12="B210"),1))))),SUM(INDEX(B2:B12,N(IF(1,AGGREGATE({15,14},6,ROW(A2:A12)-ROW(A1)/(A2:A12="B211"),1))))))
    Hi Bosco,
    Thank for your help but I need for a generic formula. With it we can solved not for only 2 codes.

    Quote Originally Posted by jason.b75 View Post
    Found a way to get your 2 column array, but there is still work to do. ... I've done it using a different approach, with 5 functions nested inside the first array of MMULT without transposing ...
    I was think about it too. But I still not get it to work.

    Quote Originally Posted by AliGW View Post
    The thread to which Jason refers is here: https://www.excelforum.com/excel-for...n-the-fly.html
    Thank, Ali. Very useful link. Although it seems not related with this topic but i've learn about using array value for vlookup with {1} technique.
    Last edited by AliGW; 08-26-2018 at 11:24 AM.

  37. #37
    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,888

    Re: Formula to convert 1 column/row to matrix

    It is related to this topic, I can assure you, because Jason has solved your problem using the techniques discussed there and shared that solution with me.

    As this is homework, he won't share his solution with you here until after you have posted the solution given by your teacher. However, if you post ideas that you might have regarding the VLOOKUP trick, I am sure he will let you know if you are on the right track or not.

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below.

  38. #38
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    You say that the link is not related, but the method using {1} is the one that I have used to get the correct answer to your question

    Try rethinking your arrays

    MMULT({-2.8;-2.8;-2.8;-2.8;-2.8;-2.5;-2.5;-2.5;-2.5;-2.5;-2.5,-17.8;-17.8;-17.8;-17.8;-17.8;-15.9;-15.9;-15.9;-15.9;-15.9;-15.9},{1;1})

  39. #39
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Jason, Ali
    Thank for the hint.
    I tried
    =VLOOKUP(T(IF({1},$B$3:$B$13,)),$B$3:$D$13,3,0) and get {-2.8;-2.8;-2.8;-2.8;-2.8;-2.5;-2.5;-2.5;-2.5;-2.5;-2.5}
    Since vlookup will return the first result so I do not know how to get -17.8 and -15.9
    May I must combine vlookup and lookup ??

  40. #40
    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,888

    Re: Formula to convert 1 column/row to matrix

    Think about the role of the four different arguments in the VLOOKUP function. One of them is the key to being able to generate an array with all of the numbers you need. Also, remember that Jason said this:

    I've done it using a different approach, with 5 functions nested inside the first array of MMULT without transposing.

  41. #41
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by congnt92 View Post
    May I must combine vlookup and lookup ??
    That's not how I did it, but it will work.

    Have you heard of approximate match with vlookup, or similar functions?

    edit:- maybe not so simple with lookup. My first working formula was to combine vlookup and lookup, but that used more functions than vlookup alone.
    Last edited by jason.b75; 08-27-2018 at 03:42 AM.

  42. #42
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Ali, Jason
    This formula work for me.
    =MIN((VLOOKUP(T(IF({1},$A$2:$A$12,)),$A$2:$B$12,2,0)+VLOOKUP(T(IF({1},$A$2:$A$12,)),$A$2:$B$12,2,1))/2)
    Data must be sorted by code A to Z.
    But i have 2 questions about this technique
    - Why we must use T formula. The code already is text by itself. I think no need to use T but the formula will not work if remove T
    - How can I use something like this
    vlookup(value, range, column, {0,1})
    so we can have a shorter formula.
    Tks.

  43. #43
    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,888

    Re: Formula to convert 1 column/row to matrix

    Well done! It's different from Jason's solution but uses the same techniques.

  44. #44
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Ali, Jason
    This formula works, too.
    =MIN(MMULT(N(OFFSET($B$1,MATCH($A$2:$A$12,$A$2:$A$12,{0,1}),)),{1;1}))
    Still do not know why we need T for vlookup and how we can using {0,1} in vlookup like match.

  45. #45
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by congnt92 View Post
    - Why we must use T formula. The code already is text by itself. I think no need to use T but the formula will not work if remove T
    Have a look at Ali's thread, the logic was discussed there.

    An array alone is of no use. {=IF(A2:A12="B211",B2:B12)} will return FALSE because there is nothing to use the array, the result will only ever be the first value in the array, however {=SUM(IF(A2:A12="B211",B2:B12))} will return -19.6 because you now have the SUM function to do something useful with the array.

    Quote Originally Posted by congnt92 View Post
    - How can I use something like this
    vlookup(value, range, column, {0,1})
    Think outside the box, T() is for text...

  46. #46
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Your formula in post #44 is impressive.

    I'm trying to break it down a bit and see if it can be used with unsorted codes.

  47. #47
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by jason.b75 View Post

    Think outside the box, T() is for text...
    Hi Jason
    +) I know T() is for text but $A$2:$A$12 already is text so why we must use T()
    We just need IF({1},$A$2:$A$12,)
    (But formula will not works. I don't know why.)
    +) We can use {0,1} for match_type in match formula. What about vlookup. I tried the same with vlookup but it just return match_type 0.
    Tks.

  48. #48
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Try reading my post again, I quoted to lines from your post with a response to each of those. It looks like you might be mixing them up.

    {0,1} is only woking in your formula with MATCH because of something else you have done, you just might not have realised it.

  49. #49
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Jason
    From the given link, I understand that T() will convert a range to "array reference", right?
    Also, my teacher show us the solution for this excercise.
    - Create a vector of start and end point of each code: {1;5;6;11} (note: area is A2:A12)
    - Convert a vector to {1,5;6,11} using AGGREGATE(15,6,vector,k) with k is a matrix like this {1,2;3,4}
    The technique is:
    (ROW(1:2)-1)*2+{1,2}
    In my example, we have 2 codes so the generic formula is (ROW(1:n)-1)*2+{1,2}
    - Using offset() to get {-2.8,-17.8;-2.5,-15.9}
    Min and MMULT will do the rest job.
    Full formula is:
    MIN(MMULT(N(OFFSET($B$1,AGGREGATE(15,6,MATCH($A$2:$A$12,$A$2:$A$12,{0,1})/($A$2:$A$12<>$A$3:$A$13),(ROW(INDIRECT("1:"&SUMPRODUCT(1/COUNTIF($A$2:$A$12,$A$2:$A$12))))-1)*2+{1,2}),)),{1;1}))

    So the thing we learn from this example just simple is technique to convert an 1 R/C array to matrix.
    Thanks Ali, Jason, Bosco, avk for your help.

    P/S: I still follow this topic to get more great methods from you.
    Tks.
    Last edited by congnt92; 08-27-2018 at 06:05 AM.

  50. #50
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by congnt92 View Post
    From the given link, I understand that T() will convert a range to "array reference", right?
    IF({1},range) creates the array, but as I stated earlier, the array alone is useless. I think to say that T() then manipulates that into something useful would be a more accurate analysis.

    Personal opinion, your formula is significantly better than your teacher's!

    Your teacher would have beaten us if the formula produced the correct result with the codes not sorted in ascending order, but given that they all fail in that respect, we get a tie.

    Your method,

    =MIN(MMULT(N(OFFSET($B$1,MATCH($A$2:$A$12,$A$2:$A$12,{0,1}),)),{1;1}))

    uses less functions and arrays, so might be slighlty more efficient in terms of processing, but I'm docking points for the use of a volatile function (something to ask your teacher about if you haven't heard that before).

    The most concise formula that I could think of was

    =MIN(MMULT(VLOOKUP(T(IF({1},$A$2:$A$12)),$A$2:$B$12,2,N(IF({1},{0,1}))),{1;1}))

    Which was the one we were hinting towards.

    Think we might need to disect your teacher's formula as well, see if we can improve it
    As it is based on AGGREGATE, I think that is your area of expertise, Bosco!

  51. #51
    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,888

    Re: Formula to convert 1 column/row to matrix

    I think the challenge is still on: can anyone crack this to work with the codes in any order?

    This has been a particularly enjoyable thread because of the working out we have seen along the way.

  52. #52
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    This behemoth variation of the 'solution' works with ascending, or descending, but not random order. Still giving that some thought.

    =MIN(MMULT(N(OFFSET($B$1,AGGREGATE(15,6,CHOOSE({1,2},MATCH($A$2:$A$12,$A$2:$A$12,0)/($A$2:$A$12<>$A$3:$A$13),(MATCH($A$2:$A$12,$A$2:$A$12,0)+COUNTIF($A$2:$A$12,$A$2:$A$12)-1)/($A$2:$A$12<>$A$3:$A$13)),(ROW(INDIRECT("1:"&SUMPRODUCT(1/COUNTIF($A$2:$A$12,$A$2:$A$12))))-1)*2+{1,2}),)),{1;1}))

  53. #53
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Hi Jason
    Your vlookup with {0,1} for match_type works fine.
    My teacher does not have any idea about random order because he build his own data in order to show us how to convert an 1R/C array to matrix.
    From the start, our data was sort A-Z or Z-A.
    If data was sort from Z-A then just change match_type to {0,-1}.

  54. #54
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    Quote Originally Posted by congnt92 View Post
    If data was sort from Z-A then just change match_type to {0,-1}.
    Sometimes it is very easy to overlook something so obvious.

    I think you should give us your homework more often, it gives us something to think about

  55. #55
    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,888

    Re: Formula to convert 1 column/row to matrix

    So can it be done with a random order in the values column?

  56. #56
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: Formula to convert 1 column/row to matrix

    It should be possible with max(row(if, but I'm having brainfreeze on simple stuff today

  57. #57
    Forum Contributor
    Join Date
    08-14-2018
    Location
    Hanoi, Vietnam
    MS-Off Ver
    2016
    Posts
    118

    Re: Formula to convert 1 column/row to matrix

    Match() requires data must be sort with a specific order for match_type 1/-1. AGGREGATE helps us avoid it.
    But at least if we are using AGGREGATE then the data must be contiguous (no need to A-Z or Z-A).
    Because AGGREGATE(15,...) sort position of start and end point of each code from smallest to largest.
    If B210 start 1, end 5, B211 start 2 end 7 then AGGREGATE will return {1,2;5,7} and then the result will not true. (it must be: {1,5;2,7})
    If the data is contiguous then this will work

    =MIN(MMULT(N(OFFSET($B$1,AGGREGATE(15,6,ROW(1:11)/((COUNTIF(OFFSET($A$2,,,ROW(1:11),),$A$2:$A$12)=1)+(COUNTIF(OFFSET($A$2,,,ROW(1:11),),$A$2:$A$12)=COUNTIF($A$2:$A$12,$A$2:$A$12))),{1,2;3,4;5,6}),)),{1;1}))

    The technique to create {1,2;3,4;5,6} we already know.
    Capture1.PNG
    Last edited by congnt92; 08-27-2018 at 10:40 PM. Reason: upload IMG

+ 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. Convert matrix to column, with label and value
    By TomHFC in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-05-2013, 01:29 PM
  2. Convert matrix into column data
    By Misheel in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-22-2013, 12:17 PM
  3. [SOLVED] Convert Matrix to multi column list
    By nipeeter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2012, 07:38 AM
  4. convert matrix to column
    By wbsimey in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-29-2012, 11:41 PM
  5. Replies: 5
    Last Post: 12-20-2010, 06:59 AM
  6. Convert Matrix to Single Column [ROW by Row]
    By K1bb5 in forum Excel General
    Replies: 2
    Last Post: 07-09-2010, 08:55 AM
  7. Macro to convert 1 column to a 13 column x N row matrix
    By DaveCLF in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-11-2010, 10:27 AM
  8. Convert a tri-matrix into a column
    By djaovnieds in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-17-2009, 04:50 AM

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