Power BI - 从同一列中的另一行查找值

问题描述 投票:0回答:2

我有下表,希望能够通过链接键将当前日期与旧日期进行比较。

链接键 类别 日期
111 当前 23 年 4 月 12 日
111 23 年 4 月 15 日
333 当前 23 年 4 月 15 日
333 23 年 4 月 16 日

一旦将旧日期作为计算列,我就知道如何计算日期差异,但如何将其变为下面的形状?我知道我必须使用链接密钥,但不确定如何使用。我无法旋转表格,因为它还用于其他视觉效果。

链接键 类别 日期 旧日期
111 当前 23 年 4 月 12 日 23 年 4 月 15 日
111 23 年 4 月 15 日 23 年 4 月 15 日
333 当前 23 年 4 月 15 日 23 年 4 月 16 日
333 23 年 4 月 16 日 23 年 4 月 16 日

然后我会在视觉效果中过滤当前类别,以便不存在重复项。

powerbi dax row lookup
2个回答
0
投票

你可以做的是在M查询中,按

Linking Key
分组,并将
Min(Date)
作为
Date
Max(Date)
作为
Old Date

查询应如下所示:

= Table.Group(#"Your_Table", {"Linking Key"}, {{"Date", each List.Min([Date]), type nullable date}, {"Old Date", each List.Max([Date]), type nullable date}})

您始终可以使用用户界面:


0
投票

您可以在 Power Query 中使用 M 语言创建超前/滞后列

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRSitWJVjI2BVNGxmDKxBxMmZqBKXMLMGUBUWJpqBQbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Number = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Number", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    #"xyz" = Table.AddColumn(#"Added Index", "Lead", each #"Added Index"{[Index]+1}[#"Number"]),
    #"Replaced Errors" = Table.ReplaceErrorValues(xyz, {{"Index", 0}}),
    #"Replaced Errors1" = Table.ReplaceErrorValues(#"Replaced Errors", {{"Lead", 0}}),
    #"abc" = Table.AddColumn(#"Replaced Errors1", "Lag", each #"Added Index"{[Index]-1}[#"Number"]),
    #"Replaced Errors2" = Table.ReplaceErrorValues(abc, {{"Lag", 0}})

in
    #"Replaced Errors2"

看这个视频: https://www.youtube.com/watch?v=eNdfs2BRid8

© www.soinside.com 2019 - 2024. All rights reserved.