我如何使我的"展平" excel公式更有活力?

时间:2017-09-29 14:24:00

标签: excel vba excel-vba excel-formula

由于在excel中工作的限制,我试图“变平”"我的数据以有效的方式设置,以优化可视化结构。

首先,我有几个数据表,如下所示:

Period   Year   Account   Account Type   Departments 1   Dpt. 2   Dpt. 3
Q1       2016   Cash      2              HR              Legal    Total
Q2       2017   Inv       1              Marketing       IT
Q3       2018   Intang    3              Accounting
Q4       2019   Debt      3

我的目标是"展平"数据列表成行;但是,我的问题是让公式只展平每个帐户的相应部门。我只想根据上表中的帐户类型为每个帐户添加相应的部门行。

例如,最终所需的输出将是(抱歉长度):

Period  Year      Account                  Department
Q1      2016      Cash                     Legal
Q1      2017      Cash                     Legal
Q1      2018      Cash                     Legal
Q1      2019      Cash                     Legal
Q2      2016      Cash                     Legal
Q2      2017      Cash                     Legal
Q2      2018      Cash                     Legal
Q2      2019      Cash                     Legal
Q3      2016      Cash                     Legal
Q3      2017      Cash                     Legal
Q3      2018      Cash                     Legal
Q3      2019      Cash                     Legal
Q4      2016      Cash                     Legal
Q4      2017      Cash                     Legal
Q4      2018      Cash                     Legal
Q4      2019      Cash                     Legal
Q1      2016      Cash                     IT
Q1      2017      Cash                     IT
Q1      2018      Cash                     IT
Q1      2019      Cash                     IT
Q2      2016      Cash                     IT
Q2      2017      Cash                     IT
Q2      2018      Cash                     IT
Q2      2019      Cash                     IT
Q3      2016      Cash                     IT
Q3      2017      Cash                     IT
Q3      2018      Cash                     IT
Q3      2019      Cash                     IT
Q4      2016      Cash                     IT
Q4      2017      Cash                     IT
Q4      2018      Cash                     IT
Q4      2019      Cash                     IT
Q1      2016      Inventory                HR
Q1      2017      Inventory                HR
Q1      2018      Inventory                HR
Q1      2019      Inventory                HR
Q2      2016      Inventory                HR
Q2      2017      Inventory                HR
Q2      2018      Inventory                HR
Q2      2019      Inventory                HR
Q3      2016      Inventory                HR
Q3      2017      Inventory                HR
Q3      2018      Inventory                HR
Q3      2019      Inventory                HR
Q4      2016      Inventory                HR
Q4      2017      Inventory                HR
Q4      2018      Inventory                HR
Q4      2019      Inventory                HR
Q1      2016      Inventory                Marketing
Q1      2017      Inventory                Marketing
Q1      2018      Inventory                Marketing
Q1      2019      Inventory                Marketing
Q2      2016      Inventory                Marketing
Q2      2017      Inventory                Marketing
Q2      2018      Inventory                Marketing
Q2      2019      Inventory                Marketing
Q3      2016      Inventory                Marketing
Q3      2017      Inventory                Marketing
Q3      2018      Inventory                Marketing
Q3      2019      Inventory                Marketing
Q4      2016      Inventory                Marketing
Q4      2017      Inventory                Marketing
Q4      2018      Inventory                Marketing
Q4      2019      Inventory                Marketing
Q1      2016      Inventory                Accounting
Q1      2017      Inventory                Accounting
Q1      2018      Inventory                Accounting
Q1      2019      Inventory                Accounting
Q2      2016      Inventory                Accounting
Q2      2017      Inventory                Accounting
Q2      2018      Inventory                Accounting
Q2      2019      Inventory                Accounting
Q3      2016      Inventory                Accounting
Q3      2017      Inventory                Accounting
Q3      2018      Inventory                Accounting
Q3      2019      Inventory                Accounting
Q4      2016      Inventory                Accounting
Q4      2017      Inventory                Accounting
Q4      2018      Inventory                Accounting
Q4      2019      Inventory                Accounting
Q1      2016      Intangibles              Total
Q1      2017      Intangibles              Total
Q1      2018      Intangibles              Total
Q1      2019      Intangibles              Total
Q2      2016      Intangibles              Total
Q2      2017      Intangibles              Total
Q2      2018      Intangibles              Total
Q2      2019      Intangibles              Total
Q3      2016      Intangibles              Total
Q3      2017      Intangibles              Total
Q3      2018      Intangibles              Total
Q3      2019      Intangibles              Total
Q4      2016      Intangibles              Total
Q4      2017      Intangibles              Total
Q4      2018      Intangibles              Total
Q4      2019      Intangibles              Total
Q1      2016      Debt                     Total
Q1      2017      Debt                     Total
Q1      2018      Debt                     Total
Q1      2019      Debt                     Total
Q2      2016      Debt                     Total
Q2      2017      Debt                     Total
Q2      2018      Debt                     Total
Q2      2019      Debt                     Total
Q3      2016      Debt                     Total
Q3      2017      Debt                     Total
Q3      2018      Debt                     Total
Q3      2019      Debt                     Total
Q4      2016      Debt                     Total
Q4      2017      Debt                     Total
Q4      2018      Debt                     Total
Q4      2019      Debt                     Total

我能够与以下公式非常接近:

=IFERROR(INDEX(Reference!$A$1:INDEX(Reference!A:A,MATCH(REPT("z",10),Reference!A:A)),INT((ROW(Reference!1:1)-1)/((COUNTA(Reference!B:B)-1)*(COUNTA(Reference!C:C)-1)*(COUNTA(Reference!D:D)-1)))+2),"")

=IF(E2<>"",INDEX(Reference!B:B,MOD(INT((ROW(Reference!1:1)-1)/((COUNTA(Reference!C:C)-1)*(COUNTA(Reference!D:D)-1))),COUNTA(Reference!B:B)-1)+2),"")

=IF(E2<>"",INDEX(Reference!C:C,MOD(INT((ROW(Reference!1:1)-1)/(COUNTA(Reference!D:D)-1)),COUNTA(Reference!C:C)-1)+2),"")

=IF(E2<>"",INDEX(Reference!D:D,MOD((ROW(Reference!1:1)-1),COUNTA(Reference!D:D)-1)+2),"")

这些公式可以完全展平数据,而不会将部门类型与帐户类型相匹配;但是,这给我留下了许多额外的行,这些行不包含任何数据并使数据非常大(因为每个部门的所有时间段都会有每个帐户的行。

我尝试使用几个额外的IF语句操作公式,以匹配帐户类型和部门类型,然后展平但无济于事。我复杂化了吗?我想我已经盯着它看了太久......如果有人有解决方案或想法来修改下面的公式,我会永远感激。

0 个答案:

没有答案