Search code examples
datepowerbidaxsubtraction

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:

enter image description here

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.

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.


Solution

  • This is fairly straight forward, add a new column:

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