如何使用强力查询为上个月的值创建新的条件列

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

这就是我在 DAX 及其工作中所做的事情

lm_cohort = CALCULATE(MAX(Dim__cluster[cohort]), ALLEXCEPT(Dim__cluster, Dim__cluster[membership_id]), PREVIOUSMONTH(Dim__cluster[month_id]))

enter image description here

无论如何我都没有找到使用电源查询或高级编辑器

有人可以帮我做到吗?谢谢你

powerbi dax powerquery
1个回答
0
投票

尝试使用以下命令创建自定义列:

let
 tbl = #"Your previous step", // change this to match your previous step in the query
 mID = [membership_id],
 prevM = Date.AddMonths([month_id], -1),
 find = Table.SelectRows(tbl, each [membership_id] = mID and [month_id] = prevM),
 result = List.First(find[cohort])
in
 result

您可以将其粘贴到新查询中的完整示例查询:

let
  Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs9MK6lKTFTSUTIw1HVJTdY1MgaynROLSxNz9D3z0opSgdyw1KJKBY/M9Awg2zG5JLMsVSlWB02vf3IJRK9PfmViTmZxCZH6/PLLyLbTsTSdLDuDUwuI0hcLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [membership_id = _t, month_id = _t, cohort = _t, basket_size_cluster = _t, #"active/inactive" = _t]),
  #"Changed column type" = Table.TransformColumnTypes(Source, {{"membership_id", type text}, {"month_id", type date}, {"cohort", type text}, {"basket_size_cluster", type text}, {"active/inactive", type text}}, "en-US"),
  #"Added custom" = Table.AddColumn(#"Changed column type", "lm_cohort", each 
    let
      tbl = #"Changed column type",
      mID = [membership_id],
      prevM = Date.AddMonths([month_id], -1),
      find = Table.SelectRows(tbl, each [membership_id] = mID and [month_id] = prevM),
      result = List.First(find[cohort])
    in
      result)
in
  #"Added custom"
© www.soinside.com 2019 - 2024. All rights reserved.