简体   繁体   English

Expression.Error:我们不能将运算符 > 应用于类型 List 和 Number

[英]Expression.Error: We cannot apply operator > to types List and Number

let
    Source = Excel.Workbook(File.Contents("C:\Users\Robert\Downloads\Assignment_Detail_Tracking_TEST.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Contractor", type text}, {"ID", Int64.Type}, {"Event Date", type date}, {"Detail Start Date", type date}, {"Detail End Date", type date}, {"Amendment Event Type", type text}, {"Amendment Reason", type text}, {"Amendment Type", type text}, {"Comment", type text}, {"Bill Rate", type number}, {"Current Start Date", type date}, {"Supplier", type text}, {"Hiring Manager", type text}, {"Tax Work Location", type text}, {"VMO", type text}, {"Detail Status", type text}, {"Longevity In Days", Int64.Type}, {"Status", type text}, {"Sub Status", type text}, {"Labor Category", type text}}),
    #"Multi Sort on Contractor Ascending and Detail Start Date Descending" = Table.Sort(#"Changed Type",{{"Contractor", Order.Ascending}, {"Detail Start Date", Order.Descending}}),
    #"Change Detail Start Date to Text" = Table.TransformColumnTypes(#"Multi Sort on Contractor Ascending and Detail Start Date Descending",{{"Detail Start Date", type text}}),
    #"Extract Building Number from Tax Work Location" = Table.AddColumn(#"Change Detail Start Date to Text", "Text Before Delimiter", each Text.BeforeDelimiter([Tax Work Location], " -"), type text),
    #"Name Building Column" = Table.RenameColumns(#"Extract Building Number from Tax Work Location",{{"Text Before Delimiter", "Building"}}),
    #"Removed Columns" = Table.RemoveColumns(#"Name Building Column",{"ID", "Event Date", "Detail End Date", "Amendment Reason", "Amendment Type", "Comment", "Bill Rate", "Current Start Date", "Hiring Manager", "VMO", "Detail Status", "Status", "Sub Status", "Longevity In Days", "Labor Category", "Tax Work Location"}),
    #"Include Only Creation and Termination" = Table.SelectRows(#"Removed Columns", each Text.Contains([Amendment Event Type], "Termination") or Text.Contains([Amendment Event Type], "Creation")),
    #"Added Index" = Table.AddIndexColumn(#"Include Only Creation and Termination", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Date Range", each if #"Added Index"[Contractor] = #"Added Index"{[Index] + 1}[Contractor] and #"Added Index"[Supplier] = #"Added Index"{[Index] + 1}[Supplier] and #"Added Index"[Building] = #"Added Index"{[Index] + 1}[Building] and Text.Contains(#"Added Index"[Amendment Event Type], "Termination") and Text.Contains(#"Added Index"{[Index] + 1}[Amendment Event Type], "Creation") then #"Added Index"{[Index] + 1}[Detail Start Date] & " - " & #"Added Index"[Detail Start Date] else if #"Added Index"[Index] > 0 and #"Added Index"[Contractor] = #"Added Index"{[Index] - 1}[Contractor] and #"Added Index"[Supplier] = #"Added Index"{[Index] - 1}[Supplier] and #"Added Index"[Building] = #"Added Index"{[Index] - 1}[Building] and Text.Contains(#"Added Index"[Amendment Event Type], "Creation") and Text.Contains(#"Added Index"{[Index] - 1}[Amendment Event Type], "Termination") then #"Added Index"[Detail Start Date] & " - " & #"Added Index"{[Index] - 1}[Detail Start Date] else if Text.Contains(#"Added Index"[Amendment Event Type], "Creation") then #"Added Index"[Detail Start Date] & " - " & DateTime.LocalNow() else null),
    #"Date Range" = #"Added Custom"{0}[Date Range]
in
    #"Date Range"

I am fairly new to Power Query but am working with a data set with employee assignment details.我是 Power Query 的新手,但正在处理包含员工分配详细信息的数据集。 I have imported the spreadsheet and formatted the data such that for every employee there will be multiple rows per employee (one for hiring date and another for termination date if applicable), and I am hoping to find some way to consolidate these rows.我已经导入了电子表格并格式化了数据,这样对于每个员工,每个员工都有多行(一个用于雇用日期,另一个用于终止日期,如果适用的话),我希望找到某种方法来合并这些行。 I decided to create a custom column that will make sure that for any given row, if the next/previous row has the same employee, temp agency, and building are the same and there is a creation and termination date, then a date range will be created.我决定创建一个自定义列,以确保对于任何给定行,如果下一行/上一行具有相同的员工、临时代理机构和建筑物,并且有创建和终止日期,那么日期范围将被创建。

I am running into errors with creating the custom column due to various columns being treated as lists.由于各种列被视为列表,我在创建自定义列时遇到了错误。 Converting the data type of the column doesn't work, and other threads that have a similar error seem to incorporate data types (numbers, text) at the level of a value whereas tables, records and lists are different.转换列的数据类型不起作用,其他有类似错误的线程似乎在值级别合并数据类型(数字、文本),而表、记录和列表则不同。 I have read documentation but am still confused on how I should proceed.我已经阅读了文档,但仍然对我应该如何进行感到困惑。 I have made sure the columns are of the appropriate data type for my formula, and I'm not getting any syntax errors.我已确保列的数据类型适合我的公式,而且我没有收到任何语法错误。 The error is specifically happening with该错误具体发生在

else if #"Added Index"[Index] > 0

on line 13 since Index is being treated as a list, but even if I remove that, I get similar errors for other columns.在第 13 行,因为 Index 被视为一个列表,但即使我删除它,其他列也会出现类似的错误。 Perhaps I have just missed something important when loading excel data but would appreciate any help.也许我在加载 excel 数据时刚刚错过了一些重要的事情,但希望得到任何帮助。

Well, to get you started, you can't do this, which compares a list to an item in a list:好吧,为了让你开始,你不能这样做,它将列表与列表中的项目进行比较:

 if #"Added Index"[Contractor] = #"Added Index"{[Index] + 1}[Contractor] 

you would need to do你需要做

if #"Added Index"{[Index]}[Contractor] = #"Added Index"{[Index] + 1}[Contractor] 

and similar和类似的

You might also have better luck writing and testing your formula in pieces您可能还会更幸运地编写和测试您的公式

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

相关问题 Expression.Error:我们不能将运算符 &amp; 应用于数字和数字类型 - Expression.Error: We cannot apply operator & to types Number and Number Expression.Error:我们不能将运算符 &lt; 应用于 Function 和 Number 类型 - Expression.Error: We cannot apply operator < to types Function and Number Excel [Expression.Error] 我们不能将运算符 &lt; 应用于文本和日期类型 - Excel [Expression.Error] We cannot apply operator < to types Text and Date Expression.Error:我们无法将值(函数)转换为逻辑类型 - Expression.Error: We cannot convert the value (Function) to type Logical Expression.Error:我们无法将 null 值转换为 Text 类型。 详细信息:值= 类型=类型 - Expression.Error: We cannot convert the value null to type Text. Details: Value= Type=Type Expression.Error电源查询EXCEL - Expression.Error Power Query EXCEL Power Query: Expression.Error: 枚举中没有足够的元素来完成操作。 (列表) - Power Query: Expression.Error: There weren't enough elements in the enumeration to complete the operation. (LIST) 为什么对上一行中的值的引用会抛出此Expression.Error? - Why does a reference to a value in previous row throw this Expression.Error? Expression.Error 找不到记录的字段“xxxx” - Expression.Error The field 'xxxx' of the record wasn't found Power Query Excel 如何跨过 Expression.Error - Power Query Excel how to step over Expression.Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM