Important Community update: The process for changing your account details was updated on June 25th. Learn how this impacts your Community experience and the actions we suggest you take to secure your account here.

Alteryx Designer Desktop Discussions

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

Rewrite VBA-Code in Alteryx

Entity1710
5 - Atom

Hello friends,

I have the following VBA code for a small university project that I need to write in Alteryx:


Public Function Smolders (x As Variant) As Date
If IsNull (x) Or x = " " Then Smolders = "1.1.1930"
Exit Function
End If

Smolders = 5 - Weekday (x, 2)+ x
If Smolders > x Then Smolders = Smolders - 7
End Function


Can someone explain to me exactly how to do this? I need to rewrite this for a specific column called "BottleStart" which represents a date. I have already tried to get Chatgbt to explain it to me, but he only comes up with errors. I hope you can help me. Thanks in advance

Best regards

4 REPLIES 4
caltang
17 - Castor
17 - Castor

X refers to your field or dimension from your dataset - in this case Smolders. It's forming the data type as "Date", and the formula equivalent in Alteryx is:

IF IsNull([Smolders])
OR [Smolders] = ""
THEN [Smolders] = "1930-01-01"
ELSE [Smolders]
ENDIF

 

In this case, I believe X is referencing a field called Smolders as well, just so happen then it's formatting the value to be 1st Jan 1930 if it's null or empty. 

 

The other function I think is safer to create a new field. In this case BottleStart.

The Weekday(x,2) function refers to the day of the week, and the 2 represents 1-7 (Monday = 1, Sunday = 7).

 

I'll need more data to confirm this. Can you provide some sample data and expected columns + their expected values? Easier to re-engineer that way.

 

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Entity1710
5 - Atom

Hey Calvin,

thanks for the fast feedback. So I need a new column called "Off1" and the function is mainly related to "BottleStart". For example (see attachment) I have a date and depending on which day of the week it is, a certain number is subtracted. At least that's what I understand from Chatgbt.

Entity1710
5 - Atom

Anyone?

Hello, you need to write it in For Next loop till 7 weekdays, this is what i understood with your query

Labels