在 Power BI 中通过使用 Dax 查找两行之间的差异 [英] Find difference between two rows by usind Dax in Power BI

查看:76
本文介绍了在 Power BI 中通过使用 Dax 查找两行之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有三列,第一列是 ID(ID 相同)第二列是金额,第三列是日期,我想要两行之间的差异(金额)

I have three column one is Id(ID is same) 2nd col is amount and third is date, I want difference between two rows(amount)

推荐答案

由于想得到ID相等的日期的前一个值,可以使用如下:

As you want to have the previous value of the date where the ID is equal, you can use the following:

添加一列,

Column4 = 
    var baseFilter = FILTER(DiffRows;DiffRows[Column1] = EARLIER(DiffRows[Column1]))
    var selectDate = CALCULATE(LASTDATE(DiffRows[Column3]);baseFilter; 
        FILTER(baseFilter; DiffRows[Column3] < EARLIER(DiffRows[Column3])))
 return 
     DiffRows[Column2] - CALCULATE(sum(DiffRows[Column2]);baseFilter; 
     FILTER(baseFilter; DiffRows[Column3] =selectDate))

首先我创建一个基本过滤器以确保 ID 相同.接下来,我选择相同 id 集中的上一个日期的日期最后我使用这个日期,从行中过滤出正确的值.

First I create a basefilter to ensure the IDs are same. Next I select the date whcih is the previousdate within the set of same ids Last I use this date, to filter the correct value out of the rows.

最终结果:

这篇关于在 Power BI 中通过使用 Dax 查找两行之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆