1

I would like to map a table replacing some data based on data from another cell..

In my below example I would like to remove data from the "Status" column if the cell to the left on the "price" column is empty.

I know it is possible to do it very simply duplicating the table and having a simple =IF formula manually placed where needed, here I try to see how I can achieve this in only one single formula; I managed to do it but my solution is quite complex

Start table

Price Status Price Status Price Status
12 Paid 23 Forecasted Forecasted
Paid 22 Forecasted 7 Forecasted
30 Paid 10 Forecasted 15 Forecasted
5 Paid 7 Forecasted 30 Forecasted
10 Paid 40 Forecasted 6 Forecasted
10 Paid 5 Forecasted 8 Forecasted
2 Paid Forecasted 9 Forecasted
4 Paid Forecasted Forecasted

Desired output

As you can see I want to remove the "Paid" "Forecasted" values when its corresponding left cell is empty too

Price Status Price Status Price Status
12 Paid 23 Forecasted
22 Forecasted 7 Forecasted
30 Paid 10 Forecasted 15 Forecasted
5 Paid 7 Forecasted 30 Forecasted
10 Paid 40 Forecasted 6 Forecasted
10 Paid 5 Forecasted 8 Forecasted
2 Paid 9 Forecasted
4 Paid

I managed to do it with the following function: =WRAPROWS(TOCOL(BYROW(WRAPROWS(TOCOL(A2:F9;0;0);2);LAMBDA(x;if(left(join("/";x);1)="/";"";x)));0;0);6) but as stated above.. this may be over complex, there is surely a more simple way. I wanted to use a =MAP formula but could not figure out how to manage the empty or not condition from left cell and apply it to the right cell

Thanks very much

2
  • May I ask if the actual table has 6 columns and not 2? Also, do you not want the blank cells removed?
    – PatrickdC
    Commented Dec 10 at 17:50
  • Yes the table structure got 6 cols and I do need to keep the blank cells
    – Alex M
    Commented Dec 11 at 8:58

2 Answers 2

1

An IF formula can be used surgically with OFFSET to manipulate the data as needed:

=ARRAYFORMULA(HSTACK(A1:A9,IF(A1:E9<>"",B1:F9,)))

If A1:F9 is the data set, we get A1:E9 with the last column removed. If that is not empty, We use B1:F9 as the result, with the first column removed from the range. By using IF this way, we have the desired result except the first column, which we Horizontally STACK it as is later.

Price Status Price Status Price Status
$12.00 Paid 23 Forecasted
22 Forecasted 7 Forecasted
$30.00 Paid 10 Forecasted 15 Forecasted
$5.00 Paid 7 Forecasted 30 Forecasted
$10.00 Paid 40 Forecasted 6 Forecasted
$10.00 Paid 5 Forecasted 8 Forecasted
$2.00 Paid 9 Forecasted
$4.00 Paid
3
  • Hello, I would have not think of that, thanks! I still wonder if there would be a way of doing it using MAP formula
    – Alex M
    Commented Dec 11 at 9:35
  • @AlexM Not as elegant as my IF, but as a theoretical exercise: =LET(d,WRAPROWS(TOCOL(A2:F9),2),m, MAP(INDEX(d,,1),INDEX(d,,2),LAMBDA(a,l, IF(a="",{"",""},{a,l}))), WRAPROWS(TOCOL(m),6))
    – TheMaster
    Commented Dec 11 at 11:44
  • Thanks very much that is what I looked for in terms of logic!! PS: I add to make a quick fix to the IF replacing ";" by "\" IF(a="";{""\""};{a\l}) so it worked, it may be related to my sheet settings. =LET(d,WRAPROWS(TOCOL(A1:F8),2),m, MAP(INDEX(d,,1),INDEX(d,,2),LAMBDA(a,l, IF(a="",{""\""},{a\l}))), WRAPROWS(TOCOL(m),6))
    – Alex M
    Commented 2 days ago
1

Use QUERY

First of all, if I understood you correctly, you just want to use formulas which are relatively simple or readable. With this, I suggest you try and use the QUERY function. However, it does remove all empty cells (based on the price column) due to the query SELECT * WHERE Col1 IS NOT NULL.

Solutions

1. WRAPROWS + LET + QUERY

(NOTE: this solution does not include the headers while the data are arranged differently since the data pairs were shifted to fill in the empty cells)

Formula:
=LET(a; WRAPROWS(TOCOL(A2:F9);2);
     b; QUERY(a;"SELECT * WHERE Col1 IS NOT NULL");
     IFNA(WRAPROWS(TOCOL(b);6)))
Output:
12 Paid 23 Forecasted 22 Forecasted
7 Forecasted 30 Paid 10 Forecasted
15 Forecasted 5 Paid 7 Forecasted
30 Forecasted 10 Paid 40 Forecasted
6 Forecasted 10 Paid 5 Forecasted
8 Forecasted 2 Paid 9 Forecasted
4 Paid

2. LET + QUERY

Formula:
=LET(a; QUERY(A1:B9;"SELECT * WHERE Col1 IS NOT NULL");
     b; QUERY(C1:D9;"SELECT * WHERE Col1 IS NOT NULL");
     c; QUERY(E1:F9;"SELECT * WHERE Col1 IS NOT NULL");
     IFNA(HSTACK(a;b;c)))
Output:
Price Status Price Status Price Status
12 Paid 23 Forecasted 7 Forecasted
30 Paid 22 Forecasted 15 Forecasted
5 Paid 10 Forecasted 30 Forecasted
10 Paid 7 Forecasted 6 Forecasted
10 Paid 40 Forecasted 8 Forecasted
2 Paid 5 Forecasted 9 Forecasted
4 Paid

References

2
  • Feel free to ask anything about the answer posted above.
    – PatrickdC
    Commented Dec 10 at 20:19
  • Thanks very much for your input, as I do need to keep the blank cells I will be a bit limited
    – Alex M
    Commented Dec 11 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.