简体   繁体   English

如何根据excel中的变量自动更改引用

[英]How to automatically change reference based on variable in excel

So I'm trying to create a Forecast using historic data from 2 years.因此,我正在尝试使用 2 年的历史数据创建预测。 Each year's data is broken down into weeks and weeks that haven't occurred yet are set to 0. I'm struggling trying to create a formula that will automatically run a Forecast on only the weeks in the year that have occurred.每年的数据都被分解为周,尚未发生的周设置为 0。我正在努力创建一个公式,该公式将仅在一年中发生的周自动运行预测。 I created this formula which Excel won't execute:我创建了这个 Excel 不会执行的公式:

=UNIQUE(FILTER(WkSht!G:(VLOOKUP(F1,DH2:DI54,2)),(WkSht!A:A)=(B1)))

I'm trying to use VLOOKUP to replace the second part of a cell reference based off a lookup table.我正在尝试使用 VLOOKUP 来替换基于查找表的单元格引用的第二部分。 So if F1 is 25, for example, then the Filter function will be:因此,例如,如果 F1 为 25,则 Filter 函数将为:

=UNIQUE(FILTER(WkSht!G:AE,(WkSht!A:A)=(B1))

That second formula works on its own as intended, but I'm trying to create this excel file so that it requires minimal work to update in the future and manually changing the range seems like a bit too much work to expect other people to do.第二个公式按预期自行工作,但我正在尝试创建这个 excel 文件,以便将来需要最少的工作来更新它,手动更改范围似乎有点太多的工作期望其他人做。

So I guess my question is: How do I change part of the reference automatically?所以我想我的问题是:如何自动更改部分参考? Maybe I could do:也许我可以这样做:

=UNIQUE(FILTER(VLOOKUP(F1,DH2:DI54,2)),(WkSht!A:A)=(B1)))

And have to lookup values contain the reference text?并且必须查找包含参考文本的值? Alternatively, is there a way to filter out the last of the 0's in the FORECAST.ETS function (as some values might intentionally be 0s in earlier weeks)?或者,有没有办法过滤掉 FORECAST.ETS 函数中的最后一个 0(因为某些值可能在前几周故意为 0)?

To get a variable width range, you can use the construct要获得可变宽度范围,您可以使用构造

SomeRange:INDEX(MaxRange,,NumberOfColumns)

In your case SomeRange would be在你的情况下SomeRange将是

WkSht!G:G

MaxRange would be something like MaxRange将类似于

WkSht!G:Z

where you replace Z with a column that comfortably covers all your (future) data您将Z替换为舒适地涵盖所有(未来)数据的列

NumberOfColumns is your VLookup (You probably want an exact match?, If so include the 4th parameter = 0 ) NumberOfColumns是您的VLookup (您可能想要完全匹配?,如果是这样,请包括第 4 个参数 = 0

Demo:演示:

=UNIQUE(FILTER(WkSht!G:G:INDEX(WkSht!G:Z,,VLOOKUP(F1,DH2:DI54,2,0)),WkSht!A:A=B1))

在此处输入图像描述

Sample data on sheet WkSht WkSht表上的示例数据

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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