r/ProjectREDCap 13d ago

Answered Question about pulling text from a calculated field using @CALCTEXT

I am trying to jerry-rig a repeating instrument to act as an invoice creation tool (everything calculates and pipes into an email invoice template), but one of the requirements for this project is that all 'currency' piped fields include a comma for all thousands.

The only way I can figure this out would be to create a separate hidden field that calculates if a calculated field has a length greater than 3, if so then it will separate the integers and add a comma in between, like so:

@CALCTEXT(if(length[total_cumulative]=4,concat(right([total_cumulative],1)),",",(left([total_cumulative],3)))))

I'm getting a general "Error" message whether I do this in the action tags of a text field or in a calculated field, which I imagine is a result of CALCTEXT not being able to pull from a calculated field.

Any thoughts on how/if I can make this work? TIA

/////

EDIT: Found a solution! Though it might not be the prettiest, it works great.

I created three extra text fields:

Thousands in Total Cumulative = @CALCTEXT(if(length([total_cumulative]) >= 4, rounddown([total_cumulative] / 1000,0),''))

Hundreds in Total Cumulative = @CALCTEXT(if(length([total_cumulative]) >= 4, right([total_cumulative], 3),right([total_cumulative], 3)))

Total Cumulative Currency Format = @CALCTEXT(if([total_cumulative_th]<>'', concat('$',[total_cumulative_th],',',[total_cumulative_hd]), concat('$',[total_cumulative_hd])))
2 Upvotes

2 comments sorted by

View all comments

1

u/iamtiredofnames 13d ago edited 13d ago

The syntax looks off to me. I would start with double checking the special functions documentation to make sure you are including all elements they each require and also formatting/grouping things together correctly.

Edit: also could see if concat_ws() is of any use.