简体   繁体   English

Power Bi,Dax 语法,用于从具有重复日期的列中减去具有条件的 TODAY 日期

[英]Power Bi, Dax Syntax to subtract TODAY date with criteria from a column with repeated dates

The problem is, I have table with products, their "adresses" and the expiration date, just like below:问题是,我有一个包含产品、它们的“地址”和有效期的表格,如下所示:

Table Image表格图片

I need to show the "days to expire" in a matrix-visual so I tried to make a DAX formula as it goes trying to get the "days to expire" from each product and it's expiration date uniquely, but the result was way far from what i wanted.我需要在矩阵视觉中显示“到期天数”,因此我尝试制作一个 DAX 公式,因为它试图从每个产品中获取“到期天数”并且它的到期日期是唯一的,但结果很远从我想要的。

DaysToExpire = CONVERT(SUM(Venda_Abast_Venc[DTVALIDADE]) - TODAY(), INTEGER)

It resulted in the sum of all the expirations dates by product and subtracted by the Today() date, the number was really higher than the real value when I needed it uniquely.结果是按产品计算所有到期日期的总和并减去 Today() 日期,当我唯一需要它时,该数字确实高于实际值。

这是相当简单的,添加一个新列:

DaysToExpire = DateDiff(Today(), Venda_Abast_Venc[DTVALIDADE], DAY)

The problem is: what happens if your matrix selection brings more than one product with different expiration dates?问题是:如果您的矩阵选择带来了不止一种具有不同有效期的产品,会发生什么? Assuming the safest option, I'll use the minimum expiration date.假设最安全的选项,我将使用最短到期日期。

DaysToExpire =
INT( MIN( Venda_Abast_Venc[DTVALIDADE] ) - TODAY() )

this way dates are not summed up and just one date is selected for the computation这样日期不会相加,只选择一个日期进行计算

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM