Expression.Error:我们无法将值 3 转换为函数类型
Posted
技术标签:
【中文标题】Expression.Error:我们无法将值 3 转换为函数类型【英文标题】:Expression.Error: We cannot convert the value 3 to type Function 【发布时间】:2021-03-11 19:26:52 【问题描述】:在此代码中需要一些帮助。不知怎的,我弄错了语法:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdE7CsMwFETRrRjVBuk9fV1KK0hvXCYQCAhi758YnCoEdMuBU91ZV+OdFbHqzGxu/X08+uvZp1rrueu+349JzDYDpox5xgJjkbHEWGasMLZcTKwoyDtiyphnLDAWGUuMZcYKY1deidadL8gg75ApY56xwFhkLDGWGSuMffOmP6y19sN0QS8MmTLmGQuMRcYSY5mxwtiZd/sA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Portofolio = _t, Asset = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,"Date", type date),
#"Sorted Rows" = Table.Sort(#"Changed Type","Asset", Order.Ascending,"Date", Order.Ascending),
#"Grouped Rows" = Table.Group(#"Sorted Rows", "Asset", "t_Asset", each _, type table [Date=nullable text, Portofolio=nullable text, Asset=nullable text]),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Row-1", each Table.SelectRows([t_Asset], Table.RowCount([t_Asset])-1))
in
#"Added Custom"
error image
这是我期望实现的目标。
Example
我刚刚想通了!感谢那些试图提供帮助的人!
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdE7CsMwFETRrRjVBuk9fV1KK0hvXCYQCAhi758YnCoEdMuBU91ZV+OdFbHqzGxu/X08+uvZp1rrueu+349JzDYDpox5xgJjkbHEWGasMLZcTKwoyDtiyphnLDAWGUuMZcYKY1deidadL8gg75ApY56xwFhkLDGWGSuMffOmP6y19sN0QS8MmTLmGQuMRcYSY5mxwtiZd/sA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Portofolio = _t, Asset = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,"Date", type date),
#"Sorted Rows" = Table.Sort(#"Changed Type","Asset", Order.Ascending,"Date", Order.Ascending),
#"Grouped Rows" = Table.Group(#"Sorted Rows", "Asset", "t_Asset", each _, type table [Date=nullable text, Portofolio=nullable text, Asset=nullable text]),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "t_Index", each Table.AddIndexColumn([t_Asset], "Index", 1, 1, Int64.Type)),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom","t_Asset"),
#"Added Custom1" = Table.AddColumn(#"Removed Columns", "Portfolio", each Table.SelectRows([t_Index],(Innertable)=> Innertable[Index] = Table.RowCount([t_Index])-1)),
#"Removed Columns1" = Table.RemoveColumns(#"Added Custom1","t_Index"),
#"Expanded Portfolio" = Table.ExpandTableColumn(#"Removed Columns1", "Portfolio", "Portofolio", "Portofolio")
in
#"Expanded Portfolio"
【问题讨论】:
【参考方案1】:您是否尝试从上一行获取 t_asset 表?
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdE7CsMwFETRrRjVBuk9fV1KK0hvXCYQCAhi758YnCoEdMuBU91ZV+OdFbHqzGxu/X08+uvZp1rrueu+349JzDYDpox5xgJjkbHEWGasMLZcTKwoyDtiyphnLDAWGUuMZcYKY1deidadL8gg75ApY56xwFhkLDGWGSuMffOmP6y19sN0QS8MmTLmGQuMRcYSY5mxwtiZd/sA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Portofolio = _t, Asset = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,"Date", type date),
#"Sorted Rows" = Table.Sort(#"Changed Type","Asset", Order.Ascending,"Date", Order.Ascending),
#"Grouped Rows" = Table.Group(#"Sorted Rows", "Asset", "t_Asset", each _, type table [Date=nullable text, Portofolio=nullable text, Asset=nullable text]),
#"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Row-1", each try #"Added Index"[Index]-1[t_Asset] otherwise null)
in #"Added Custom"
【讨论】:
嗨,我正在尝试从每个表中获取最后的负 1 条记录。 您从三列开始——日期、投资组合、资产。您对资产进行分组。您想在第 2 行显示第 1 行的哪些字段?以上已经完成了整个表格请发布所需的示例输出【参考方案2】:如果需要获取表格的倒数第二行(作为表格),最后一步应该是这样的:
= Table.AddColumn(#"Grouped Rows", "Row-1", each Table.LastN(Table.RemoveLastN([t_Asset]),1))
如果您的目标是获得一个表格,其中包含每个资产的倒数第二行,那么您可以使用以下代码:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdE7CsMwFETRrRjVBuk9fV1KK0hvXCYQCAhi758YnCoEdMuBU91ZV+OdFbHqzGxu/X08+uvZp1rrueu+349JzDYDpox5xgJjkbHEWGasMLZcTKwoyDtiyphnLDAWGUuMZcYKY1deidadL8gg75ApY56xwFhkLDGWGSuMffOmP6y19sN0QS8MmTLmGQuMRcYSY5mxwtiZd/sA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Portofolio = _t, Asset = _t]),
types = Table.TransformColumnTypes(Source,"Date", type date),
group = Table.Group(types, "Asset", "temp", each let a = Table.Sort(_,"Date",0)
in aTable.RowCount(_)-2),
expand = Table.ExpandRecordColumn(group, "temp", "Date", "Portofolio")
in
expand
【讨论】:
谢谢。请看我的原帖。刚刚想通了。以上是关于Expression.Error:我们无法将值 3 转换为函数类型的主要内容,如果未能解决你的问题,请参考以下文章
Excel [Expression.Error] 我们不能将运算符 < 应用于文本和日期类型
无法将 '(<expression error>)' 从 '<brace-enclosed initializer list>' 转换为 std::unique_ptr<
无法使用 Ucanaccess 3.0.6 将值插入 access 97。它显示访问是只读的
ADO.NET SqlCommand:无法将值 NULL 插入列