Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

Extracting numbers before decimal point

ssubramanian
8 - Asteroid

Hi,

 

I am trying to extract the last 3 digits before decimal point from a fixed decimal column.

 

For eg, if the number is 12345.23 , I need to extract "345" and check if it is matching with some threshold. Please suggest the formula/method to be used to achieve this.

8 REPLIES 8
MarqueeCrew
20 - Arcturus
20 - Arcturus
Regex is for strings, so you'll need to convert it. Here's a formula for you:

Regex_replace(ToString([field]),".*?(\d{1,3})\.\d+",'$1')

Cheers,

Mark
🏝
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
ssubramanian
8 - Asteroid

Thank you for the quick response. Is there any other way to do it other than Regex. I am new to Regex and find it little complicated

MarqueeCrew
20 - Arcturus
20 - Arcturus
ToNumber(Right(tostring([field],0),3))

I answered with regex because you put the regex tag.

Cheers,

Mark

Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
ssubramanian
8 - Asteroid

I din't find an appropriate label for this. My bad!

Thank you another solution, this formula rounds of the last digit before decimal. Is there a way to do this without rounding it off?

MarqueeCrew
20 - Arcturus
20 - Arcturus
I'd use the first regex formula to avoid rounding.

Find anything up to the first occurrence of 1-3 digits followed by a decimal point followed by any number of digits. The 1-3 digits is the first pattern group. Output the first group.

Cheers,

Mark
Alteryx ACE & Top Community Contributor

Chaos reigns within. Repent, reflect and restart. Order shall return.
Please Subscribe to my youTube channel.
ponraj
13 - Pulsar

Here is the sample workflow for your case. Hope this is helpful. 

 

WorkflowWorkflowInputInputResultsResults

ssubramanian
8 - Asteroid

Thank you so much for suggesting multiple ways to achieve it. It worked!

ssubramanian
8 - Asteroid

Thank you so much for attaching the workflow to make it more clear. This is exactly my scenario.

Labels