使用日期作为搜索键(但忽略一天)的vlookup

发布于 2025-02-01 12:17:22 字数 1338 浏览 2 评论 0 原文

A2范围:A包含每个月使用本月第一天的几个月。输入数据时,允许用户在该月内的任何一天输入。用户输入日期的范围由命名范围“ ear_dates_rng”定义。每个月都有相应的该月收益摘要。

因此,这里有一个可能的示例:

User Input:
1/11/2017 - $100
2/9/2017 - $250
3/21/2017 - $500

Summary:
1/1/2017 - $100
2/1/2017 - $250
3/1/2017 - $500

以前,我有一张注释,迫使用户也可以使用本月的第一天进行输入,但是我想释放它。但是,这导致我的vlookup()停止工作,因为它以前使用了摘要日期来查找相应的用户输入:

= array_constrain(arrayformula(ifError(ifeREROR(vlookup(a2:a&“”& $ a $ a $ 1 $ 1 ,{ear_dates_rng&“”& ear_names_rng,ear_amounts_rng},2,false),“”)),if(count(a2:a)= 0,1,count(a2:a2:a),1),1),

我可以告诉Vlookup忽略本月的一天?

或者,当我在公式中创建数组时,有一种方法可以以某种方式使用eomonth()技巧将用户输入日期转换为本月的第一个,但是我使用命名范围的事实可能会给我带来另一个问题克服。

但是,我可以看到已经需要一个辅助列的解决方案,该解决方案可以转换ear_dates_rng中的所有日期,然后使用该公式使用该转换范围来创建数组,但是如果可能的话,我想避免使用助手列。

感谢我能得到的任何帮助!

屏幕截图示例:

输出:

[“

一月和三月的用户输入不使用本月的第一天,而二月和四月则不使用。因此,在第一张图像中,一月和三月的值在C列中为空白,而2月和4月则出现。

我的vlookup()在第一个图像的C列中,应该在第二张图像中抓住列的相应值。

The range A2:A contains months where each month uses the first day of the month. Users are allowed to input any day within that month when entering their data. The range of user input dates is defined by the named range "EAR_DATES_RNG". Each month has a corresponding summary of earnings for that month.

So here is an example of what this might look like:

User Input:
1/11/2017 - $100
2/9/2017 - $250
3/21/2017 - $500

Summary:
1/1/2017 - $100
2/1/2017 - $250
3/1/2017 - $500

Previously, I had a note forcing users to also use the first day of the month for their inputs, however I would like to free that up. However, this has caused my VLOOKUP() to stop working as it was previously using the summary date to find the corresponding user input:

=ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(VLOOKUP(A2:A&" "&$A$1,{EAR_DATES_RNG&" "&EAR_NAMES_RNG,EAR_AMOUNTS_RNG},2,false),"")), IF(COUNT(A2:A)=0,1,COUNT(A2:A)),1)

How could I instead tell VLOOKUP to ignore the day of the month?

Or maybe there is a way I could somehow convert the user input dates to the first of the month using EOMONTH() tricks when I create the array in the formula, however maybe the fact that I use a named range will pose another problem for me to overcome.

I can however, see a solution already that would require a helper column that converts all the dates in EAR_DATES_RNG and then the formula creates the array using that converted range instead, but I would like to avoid a helper column if possible.

Appreciate any help I can get with this!

Screenshot examples:

OUTPUT:

[VLOOKUP SHEET1

INPUT:

USER IMPORT SHEET

January and March user inputs do not use the first day of the month, while February and April do. So as a result, in the 1st image, January and March values are blank in Column C, while February and April are showing up.

My VLOOKUP() is in Column C of the first image and is supposed to be grabbing the corresponding values of Column G in the second image.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

胡大本事 2025-02-08 12:17:22

尝试:

=ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(VLOOKUP(TEXT(A2:A, "m/1/e")*1&" "&$A$1, 
 {EAR_DATES_RNG&" "&EAR_NAMES_RNG, EAR_AMOUNTS_RNG}, 2, 0))), 
 IF(COUNT(A2:A)=0, 1, COUNT(A2:A)), 1)

或:

=ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(VLOOKUP(A2:A&" "&$A$1, 
 {TEXT(EAR_DATES_RNG, "m/1/e")*1&" "&EAR_NAMES_RNG, EAR_AMOUNTS_RNG}, 2, 0))), 
 IF(COUNT(A2:A)=0, 1, COUNT(A2:A)), 1)

try:

=ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(VLOOKUP(TEXT(A2:A, "m/1/e")*1&" "&$A$1, 
 {EAR_DATES_RNG&" "&EAR_NAMES_RNG, EAR_AMOUNTS_RNG}, 2, 0))), 
 IF(COUNT(A2:A)=0, 1, COUNT(A2:A)), 1)

or:

=ARRAY_CONSTRAIN(ARRAYFORMULA(IFERROR(VLOOKUP(A2:A&" "&$A$1, 
 {TEXT(EAR_DATES_RNG, "m/1/e")*1&" "&EAR_NAMES_RNG, EAR_AMOUNTS_RNG}, 2, 0))), 
 IF(COUNT(A2:A)=0, 1, COUNT(A2:A)), 1)
一个人的旅程 2025-02-08 12:17:22

这是您想要的函数的脚本版本。

function firstOfTheMonth() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  //Gets the values of column A until the last row with data
  var range = sheet.getRange(2,1, sheet.getLastRow() - 1, 1);

  //Changes the date values of column A into MM-YYYY-1
  // You need to define your TimeZone on Utilities.formatDate(new Date(y), "YOUR TIMEZONE HERE", "MM-1-yyyy")
  var val = range.getValues();
  var newval = val.map(x => x.map(y => Utilities.formatDate(new Date(y), "GMT+8", "MM-1-yyyy")));

  console.log(newval);
  range.setValues(newval); 
}

您可以在OneDit触发器上手动添加该功能,以便每当在电子表格上进行编辑时,该功能就会自动运行。

之前:

“在此处输入图像描述”

​:

https:// https:// https:// developers.google.com/apps-script/reference/utilities/utilities#formatdate(Date,String,String)

Here is a script version of the function you want.

function firstOfTheMonth() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getActiveSheet();

  //Gets the values of column A until the last row with data
  var range = sheet.getRange(2,1, sheet.getLastRow() - 1, 1);

  //Changes the date values of column A into MM-YYYY-1
  // You need to define your TimeZone on Utilities.formatDate(new Date(y), "YOUR TIMEZONE HERE", "MM-1-yyyy")
  var val = range.getValues();
  var newval = val.map(x => x.map(y => Utilities.formatDate(new Date(y), "GMT+8", "MM-1-yyyy")));

  console.log(newval);
  range.setValues(newval); 
}

You can manually add the function on an onEdit Trigger so that the function will automatically run whenever an edit is made on the spreadsheet.

enter image description here

Before:

enter image description here

After the script was ran:

enter image description here

Reference:

https://developers.google.com/apps-script/reference/utilities/utilities#formatDate(Date,String,String)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文