简体   繁体   中英

How do I look up the same values from a range, multiple times with ArrayFormula

I have this range...A1:D5

在此处输入图片说明

I want to look up the rows where b = "salary" and place them in a new table. That part is pretty easy, and can be done many ways using query, filter, index/match, vlookup, and/or {arrays}.

The part I'm having trouble with, is that I want the initial result to be repeated a variable number of times. For example, if I wanted to search for all rows where B = "salary", and I wanted to repeat that result 3 times in the new table, i would want it to look like this....

在此处输入图片说明

I have tried this using all the above mentioned functions and techniques, and I can only ever get the first row to appear when using them in conjunction with ArrayFormula.

Some of the methods I've tried are as follows

=ARRAYFORMULA(INDEX ('Employees'!A2:D5, MATCH("salary", 'Employees'!B2:B, 0)))

=ARRAYFORMULA(VLOOKUP("salary",Employees!B2:D, {1,2,3}, FALSE))

=ARRAYFORMULA(QUERY('Employees'!A2:D, "Select * where B = 'salary'", 0))

=ARRAYFORMULA(TRANSPOSE(QUERY(TRANSPOSE(QUERY(Employees!$A$2:$D, "SELECT * WHERE B = 'salary'", 0 )),"SELECT Col"&((row(J9:J30)-1)-(ROUNDDOWN((row(J9:J30)-1)/3,0)*3))+1&"",0)))

try:

=ARRAYFORMULA(SUBSTITUTE(SPLIT(TRANSPOSE(SPLIT(REPT(TEXTJOIN("♦", 1, 
 FILTER({"♥♠"&A2:A, B2:D}, B2:B="salary")), 3), "♥")), "♦"), "♠", ))

0

Here the formula that can be used:

= iferror(arrayformula 
  (
    split ( 
      transpose (
        split (
          substitute ( 
            textjoin (
               "%",true, 
               if (
                    sequence(3)=sequence(3),
                    textjoin("%",false,filter({L2:N5,O2:O5&"$"} ,M2:M5="Salary"))
               )
            )
            ,"$%","$"
          )
          ,"$",true,false
        )
      )
      , "%", true,false
    )
  ),"")

data are in range L1:O5, Sequence(3) is how many repeat the result, symbol should be changed to your special, to avoid conflict to your data

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM