Skip to main content
Announcements
Accelerate Your Success: Fuel your data and AI journey with the right services, delivered by our experts. Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous69
Contributor II
Contributor II

Calculate Previous date value

I have tried the formulars below and they have not worked, wonder if there is something I am missing,

 

Sum({<DateField={'$(=Max(DateField)-1)'}>} ValueField)

 Below(Count(ValueField))

Labels (6)
6 Replies
marcus_sommer

Try it in this way: Sum({<DateField={"$(=date(Max(DateField)-1))"}>} ValueField)

Anonymous69
Contributor II
Contributor II
Author

Thanks, but that didn't work. Is there Anything I need to do before using this as an expression?

Chanty4u
MVP
MVP

Try this 

Sum({<DateField = {"$(=Max(DateField)-1)"}>} ValueField)

 

vinieme12
Champion III
Champion III

subtracting the date -1 will return a number, you just need to reformat it to match the formatting of the date in Datefield

 

Sum({<DateField={"$(=Date(Max(DateField)-1,'YYYY-MM-DD'))"}>} ValueField)

replace YYYY-MM-DD with the format in DateField

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
marcus_sommer

Make sure that DateField is a real date and not a timestamp and not a string. That field-values look like a date doesn't mean that they are one. Further this field needs to have the same formatting as the default-format for dates or you would need to specify the wanted formatting within date().

Anonymous69
Contributor II
Contributor II
Author

Thanks so far. To give you an example.

Here is my script presently

OrderData:
Load*
Inline [
InvoiceID|CustomerID|ProductID|Units|Date
1|Ast|1|8|01/01/2021
1|Ast|2|6|01/02/2022
2|Bet|3|10|02/01/2021
3|Diva|3|5|12/05/2021
4|Diva|4|10|02/06/2022
] (delimiter is '|');

OrderData_Temp:
Load *, Previous(Units) as Pre_Units
Resident OrderData;

Drop table OrderData;

 

 

And the output is 

Anonymous69_0-1705664565506.png

First Bet row and Diva should be blank the same way Ast first Row is blank. The code doesnt seem to understand the previous time by the category (customerID)