查询函数中的可变单元格值格式

Variable Cell Value Format In Query Function

我知道“格式”可以在查询函数中使用(即 Query(A1:G2,"Select * Format C 'MM/DD/YYY'")),但我不知道如何使用在我更复杂的查询中使用它。本质上,我希望所有选定的列都被格式化为日期“MM/DD/YYYY”,但我不能在单元格本身中执行此操作,因为此查询是基于用户输入提取数据的变量查询函数的一部分,并且只有这些列拉取是日期格式,所有其他拉取都是纯数字或文本。我尝试将格式放入自己,但它永远不起作用,或者输出给我“未找到匹配项”的 IfError False 读数。有人可以帮忙吗?

IFERROR(QUERY({Training!A3:AP},"select Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12,Col13,Col14,Col15,Col16,Col17,Col18,Col19,Col20,Col21,Col22,Col23,Col24,Col25,Col26,Col27,Col28,Col29,Col30,Col31,Col32,Col33,Col34,Col35,Col36,Col37,Col38,Col39,Col40,Col41,Col42 where "&TEXTJOIN(" and ", 1, IF(Lower(B3)<>"", "Lower(Col1) contains '"&Lower(B3)&"'", ),IF(Lower(B4)<>"", "Lower(Col2) contains '"&Lower(B4)&"'", ),If(Lower(B5)<>"", "Lower(Col6) contains '"&Lower(B5)&"'", ),IF(Lower(B7)<>"", "Lower(Col9) contains '"&Lower(B7)&"'", ),If(B6<>"",Vlookup(B6,Classes!G2:H,2,False)&" contains '"&B6&"'",),), 0), "No Matches Found")))

这可能没有帮助,但我认为问题在于 QUERY 函数中的 FORMAT 子句没有覆盖输出区域中的单元格格式。我做了一些测试,发现使用以下公式的简化版本,我可以更改输出格式,例如从 'mm/dd/yyyy' 到 'yyyy-mm-dd'.

"select Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11 
where "&TEXTJOIN(" and ", 1,
IF(Lower(B3)<>"", "Lower(Col1) contains '"&Lower(B3)&"'", ),
IF(Lower(B4)<>"", "Lower(Col2) contains '"&Lower(B4)&"'", ),
If(Lower(B5)<>"", "Lower(Col6) contains '"&Lower(B5)&"'", ),
IF(Lower(B7)<>"", "Lower(Col9) contains '"&Lower(B7)&"'", ),
If(B6<>"",Vlookup(B6,Classes!G2:H,2,False)&" contains '"&B6&"'",),
) & " Format Col9 'dd-yyyy-mm', Col11 'dd-yyyy-mm' ", 0)

但这只有在 cell/column 被格式化为自动时才有效。更糟糕的是,我还不能可靠地重现该行为。在 sheet 的另一个副本上,它不会更改格式。

无论如何,如果你想看到它的工作,这里是你的 sheet 的 link to the cell in my copy。 也许其他人会对问题和解决方法有更清晰的解释。

formatQUERY 中有错误。使用这个:

=ARRAYFORMULA(IF(B2="", "Please Select Criteria",
 IF(B2="Licenses", IFERROR(QUERY({Licensing!A3:D, 
 IF(Licensing!E3:E="",,TEXT(Licensing!E3:E,  "dd/mm/yyyy")), Licensing!F3:F, 
 IF(Licensing!G3:G="",,TEXT(Licensing!G3:G,  "dd/mm/yyyy")), Licensing!H3:H, 
 IF((Licensing!I3:AQ<>"")*(MOD(COLUMN(I3:AQ)+1, 4)=0), 
                       TEXT(Licensing!I3:AQ, "dd/mm/yyyy"), Licensing!I3:AQ)},
 "select "&JOIN(",", "Col"&ROW(3:7), "Col"&FILTER(ROW(9:43), NOT(MOD(ROW(9:43), 4)=0)))&" 
  where "&TEXTJOIN(" and ", 1, "1=1", 
 IF(LOWER(B3)="",,"lower(Col1)  contains '"&LOWER(B3)&"'"),
 IF(LOWER(B4)="",,"lower(Col2)  contains '"&LOWER(B4)&"'"),
 IF(LOWER(B5)="",,"lower(Col6)  contains '"&LOWER(B5)&"'"),
 IF(LOWER(B7)="",,"lower(Col10) contains '"&LOWER(B7)&"'"),
 IF(B6="",,"Col"&MATCH(B6, Licensing!2:2, 0)&" is not null")), 0), "No Matches Found"),

 IFERROR(QUERY({Training!A3:D, 
 IF(Training!E3:E="",, TEXT(Training!E3:E,  "dd/mm/yyyy")), Training!F3:F, 
 IF(Training!G3:AP="",,TEXT(Training!G3:AP, "dd/mm/yyyy"))},
 "select "&JOIN(",", "Col"&ROW(3:42))&" 
  where "&TEXTJOIN(" and ", 1, "1=1", 
 IF(LOWER(B3)="",,"lower(Col1) contains '"&LOWER(B3)&"'"),
 IF(LOWER(B4)="",,"lower(Col2) contains '"&LOWER(B4)&"'"),
 IF(LOWER(B5)="",,"lower(Col6) contains '"&LOWER(B5)&"'"),
 IF(B6="",,"Col"&MATCH(B6, Training!2:2, 0)&" is not null")), 0), "No Matches Found"))))