Power Query 中的 DAX EARLIER() 函数

标签 dax powerquery m

M/Power Query 中是否有与 EARLIER 等价的对象?

比如说,我有一个表格,在 DATE 列中有很多不同的日期,在 LETTER 列中有少量字母。我现在想要每个字母的最大日期。

在 DAX 中,我会使用类似 CALCULATE(MAX([Date]),FILTER(ALL(Table),[Letter]=EARLIER([Letter])) 的方法。

我如何在 M 中实现相同的目标?

谢谢

最佳答案

2 下面代码中的解决方案。请注意,每个都使用“PreviousStep”作为基础,因此这些是单独的解决方案。

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    PreviousStep = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Letter", type text}}),

    // 1. Add a column to the original table with the MaxDate for each letter
    //    "earlier"  is just the name of a function parameter; it could as well have been "x" or "MarcelBeug"
    AddedMaxDate = Table.AddColumn(PreviousStep, "MaxDate", (earlier) => List.Max(Table.SelectRows(PreviousStep, each [Letter] = earlier[Letter])[Date])),

    // 2. Group by letter and get the MaxDate for each letter
    GroupedOnLetter = Table.Group(PreviousStep, {"Letter"}, {{"MaxDate", each List.Max([Date]), type date}})
in
    GroupedOnLetter

关于Power Query 中的 DAX EARLIER() 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43069995/

相关文章:

date - 如何使用 Dax 公式将整数(112 格式)转换为日期?

excel - 将查询中的列添加到另一个查询中而不附加

excel - M(Power Query 公式语言)中开放记录类型的目的和用法

dynamic - Power Query : Table. 具有聚合列动态列表的组

powerbi - 通过变量引用列

PowerBI - 计算具有表用户值的行数

powerbi - 基于多个切片器值 Power BI 显示用户计数

powerpivot - 获取计算列中最常见的项目

excel - 使用 Power Query 将 Excel 列字母转换为数字

excel - 如何在电源查询中仅转置表的某些列?