Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Check difference between dates for a common value

Pramod91
8 - Asteroid

Hello everyone,

 

I need your help to deal with some dates in a workflow. I have the data like this -

Record IDCodePSDPED
1A435623-08-201711-04-2018
2A435612-04-201817-01-2019
3A435618-01-201928-05-2020
4A435601-06-2020-

 

Here, I need to check if the PED for each row of a Code (column 2) is 1 day earlier (-1) than the PSD of the next row for that Code. And if the difference between PED of current row and PSD of the next row for a given Code is not 1 then I should  be able to find it. (Here the record ID - 3 is an example of error I want to trace).

 

Can someone please help me with this?

8 REPLIES 8
atcodedog05
22 - Nova
22 - Nova

Hi @Pramod91 

 

Here is a workflow for the task.

Formula:

DateTimeDiff(
DateTimeParse([Row+1:PSD],"%d-%m-%Y"),
DateTimeParse([PED],"%d-%m-%Y"),
"days")

Workflow:

atcodedog05_1-1607944785689.png

Hope this helps 🙂 Feel to ask if you have any questions


If this post helps you please mark it as solution. And give a like if you dont mind 😀👍

Emil_Kos
17 - Castor
17 - Castor

Hi @Pramod91,

 

@atcodedog05 solution is cleaner as I don't know the regex but since I started to work on it I will share my solution.

 

Emil_Kos_0-1607945022171.png

The most important thing is combination of date time diff formula which will allow you to identify the time difference between two dates + multi row formula which allows us to perform actions on two or more rows at the same time.

 

I would also suggest to keep in mind that you need to sort your data correctly to make sure that everything is working correctly. 

 

Pramod91
8 - Asteroid

Hi @atcodedog05  and @Emil_Kos 

 

It works. But as I want it to calculate only if the local code (code) is same for two consecutive rows, I combined it with the IF formula like this - IF [Row+1:Local Code]=[Local Code] THEN DateTimeDiff(
DateTimeParse([Row+1:Price Start Date],"%y-%m-%d"),
DateTimeParse([Price End Date],"%y-%m-%d"),
"days") ELSE "-" ENDIF

 

But it gives me an error "The formula "Days" resulted in a string but the field is numeric. Use ToNumber(...) if this is correct." 

How should I deal with this?

atcodedog05
22 - Nova
22 - Nova

Hi @Pramod91 

 

2 possible solution. 

1. Change the datatype of days column to string in multirow formula tool.

 

atcodedog05_0-1608018718257.png

 

or

 

2. Replace "-" to Null() in else part.

 

IF [Row+1:Local Code]=[Local Code] THEN DateTimeDiff(
DateTimeParse([Row+1:Price Start Date],"%y-%m-%d"),
DateTimeParse([Price End Date],"%y-%m-%d"),
"days") ELSE "-" ENDIF

 

to

 

ELSE Null() ENDIF

 

 

Pramod91
8 - Asteroid

Thanks for all your help, it really worked!

atcodedog05
22 - Nova
22 - Nova

Happy to help 🙂 @Pramod91 

 

Cheers and Happy Analyzing 😀

 

Feel free to reach out if you face any issues 🙂

Pramod91
8 - Asteroid

Hi @atcodedog05,

 

Thanks for your solution yesterday.

 

I need your help again. I have few fields in a dataset like below:-

 

PSDPEDEXF PRICEVN EXF PRICEHOSP PRICEVN HOSP PRICEPPPLaunch DateEXF Less DiscountPPP Less DiscountHOSP Less DiscountSUDRI DATE
15/09/201731/10/2018275.26255.99--284.63-275.26284.63-25/12/2018-
01/10/201731/12/2018275.2255.94--284.57-275.2284.57-02/01/2019-
01/10/201704/12/2018235.37218.89--243.48-235.37243.48-25/12/2018-
01/10/201714/10/20171012.39941.52--1044.98----15/10/2017

10/12/2017

01/10/201714/10/20171302.481211.31--1340.98----15/10/2017-
01/10/201704/12/2018275.18255.92--284.55-275.18284.55-25/12/2018-
15/09/201731/10/2017279.25259.7--288.75----01/11/2017-
01/10/201731/12/2018235.35218.88--243.46----15/12/2018-
15/10/201704/12/2018279259.47--288.49-279288.49-25/12/2018-
15/10/201730/11/20181297.51206.67--1336----15/12/2018-
15/10/201731/10/20171011.44940.64--1044----01/11/2017-
15/10/201704/12/20181011.62940.81--1044.19-1011.621044.19-25/12/2018-
15/10/201704/12/20181298.591207.69--1337.09----15/12/2018

14/09/2016

01/11/201731/12/2018235.34218.87--243.45-235.34243.45-02/01/2019-

 

Also, I have a reference file as:-

 

Price1Price2 Date1Date2
EXF PRICEEXF Less Discount SUDPED
EXF Less DiscountVN EXF PRICE PEDPSD
HOSP PRICEHOSP Less Discount PSDRI DATE
HOSP Less DiscountVN HOSP PRICE RI DATELaunch Date
PPPPPP Less Discount   

 

What I want to do is, to check if the Price1 > Price2 and Date1 > Date2 (List of Price and Date is to be considered from the reference file)

 

Also, if Price2 is undefined (-) in data and the same field is used as Price1 on the next row then the original Price1 will be compared with the new Price2. For example, if EXF Less Discount is "-" then EXF PRICE must be greater than or equal to VN EXF PRICE. And the same logic I want to implement for Dates as well.

 

It would be a great help if you could suggest some ways to do this.

 

Thank you in advance!

atcodedog05
22 - Nova
22 - Nova

Hi @Pramod91 

 

Sorry to inform you that currently I am bit occupied. I would highly recommend you to post it as new question so that it becomes visible as new unsolved question and people can help you out.

Labels