使用Google表格公式从右到左或从底部到顶部填充单元格。

huangapple go评论73阅读模式
英文:

Fill cells right-to-left or bottom-to-top with Google Sheets formulas

问题

使用像 split(...) 这样的公式在Google表格中从左到右填充单元格。使用 transpose(...),可以从上到下填充。是否可能从右到左或从下到上填充单元格?

这是在Google表格中使用公式的外观:
使用Google表格公式从右到左或从底部到顶部填充单元格。

或者只是计算结果。
使用Google表格公式从右到左或从底部到顶部填充单元格。

我正在寻找的是在所选单元格中的公式(内容为 "a"),它向上填充。
使用Google表格公式从右到左或从底部到顶部填充单元格。

背后的原因是这样的。我有一个带有 query 的单元格:

=query(importrange(named_range, "A:E"), "select Col1, count(Col2) group by Col3 pivot Col4, Col5")

这返回一个带有行中的逗号分隔的数据透视标签 Col4(年份)和 Col5(YES/NO)的表格:

使用Google表格公式从右到左或从底部到顶部填充单元格。

我希望在上面的行中(红色单元格)放入一个公式,将数据透视标签分隔到正上方的单元格中,独立于有多少数据透视级别。

英文:

Formulas like split(...) fill cells left-to-right in Google sheets. Using transpose(...) I can fill top-to-bottom. Is it possible to fill cells "the other way round", i.e. right-to-left or bottom-to-top?

Here is how it looks like in Google Sheets with formulas
使用Google表格公式从右到左或从底部到顶部填充单元格。

or just with the result of the calculation.
使用Google表格公式从右到左或从底部到顶部填充单元格。

What I am looking for is a formula in the selected cell (content "a"), which fills upwards.
使用Google表格公式从右到左或从底部到顶部填充单元格。

The reason behind this is the following. I have cell with a query

=query(importrange(named_range, "A:E"), "select Col1, count(Col2) group by Col3 pivot Col4, Col5")

This returns a table with the pivot labels Col4(year) and Col5(YES/NO) separated by a comma along the row:

使用Google表格公式从右到左或从底部到顶部填充单元格。

I wanted to put a formula in the row above (the red cells) that separates the pivot labels in the cells just above, independent of how many pivot levels there are.

答案1

得分: 1

代码部分不需要翻译,以下是翻译好的部分:

"Array formulas in cells spilling rightwards and/or downwards is part of the fundamental 'grammar' of spreadsheets, and it's not possible to override this behavior (with the one proviso that formulas in spreadsheets in a right-to-left language will spill leftwards and downwards for obvious reasons)."

"Can you give some more details on what you are trying to achieve?"

"EDIT based on additional details: So what you can do here is to use LET to put your QUERY within a named variable, use CHOOSEROWS to extract the header from that name, prettify the header in the manner you're looking to do with TRANSPOSE/SPLIT/TRANSPOSE, then finally use an array literal to stick the pretty headers on top of the original QUERY:

=arrayformula(let(
queryresult,*YOUR QUERY*,
queryheaderrow,chooserows(queryresult,1),
prettyheader,transpose(split(transpose(queryheaderrow),",")),
{prettyheader;queryresult}))

This will work for any depth of pivot, but the order of the rows in the pretty header is based on the order you've specified in the QUERY. So to get YES/NO above 2022/2023 as you've specified in your example you might need to try pivot Col5,Col4 within the select string rather than pivot Col4,Col5 as you have done."

英文:

Array formulas in cells spilling rightwards and/or downwards is part of the fundamental 'grammar' of spreadsheets, and it's not possible to override this behaviour (with the one proviso that formulas in spreadsheets in a right-to-left language will spill leftwards and downwards for obvious reasons).

Can you give some more details on what you are trying to achieve?

EDIT based on additional details:
So what you can do here is to use LET to put your QUERY within a named variable, use CHOOSEROWS to extract the header from that name, prettify the header in the manner you're looking to do with TRANSPOSE/SPLIT/TRANSPOSE, then finally use an array literal to stick the pretty headers on top of the original QUERY:

=arrayformula(let(
queryresult,*YOUR QUERY*,
queryheaderrow,chooserows(queryresult,1),
prettyheader,transpose(split(transpose(queryheaderrow),",")),
{prettyheader;queryresult}))

This will work for any depth of pivot, but the order of the rows in the pretty header is based on the order you've specified in the QUERY. So to get YES/NO above 2022/2023 as you've specified in your example you might need to try pivot Col5,Col4 within the select string rather than pivot Col4,Col5 as you have done.

答案2

得分: 0

=LET(ζ,TOCOL(SPLIT(A1,";")),SORT(ζ,SEQUENCE(ROWS(ζ)),))

英文:

You can use:

=LET(ζ,TOCOL(SPLIT(A1,",")),SORT(ζ,SEQUENCE(ROWS(ζ)),))

huangapple
  • 本文由 发表于 2023年3月15日 17:55:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/75743061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定