Loading

STR() Function Ignores the Default Date and Number Formatting

Data pubblicazione: Apr 13, 2024
Descrizione
When you wrap date or number fields in the STR() function in calculated fields, the default number and date formatting might not be respected.

For example, if you set the default format for a date field (Default Properties > Date Format) to display only hours and minutes and then use the same field in a calculation and wrapped in the STR() function, the resulting date will display hours, minutes, and seconds.
Risoluzione
Use string functions to control date and number formatting in calculated fields. For example, the formula below will display [Profit] with a "$" sign and a comma in the thousands place. Only negative numbers will have a "-" sign.
IF ABS(SUM([Profit])) > 999
THEN 
     IF SUM([Profit]) < 0 THEN "-" ELSE "" END
     + "$"
     + LEFT(STR(FLOOR(ABS(SUM([Profit])))),LEN(STR(FLOOR(ABS(SUM([Profit])))))-3) 
     + "," 
     + RIGHT(STR(FLOOR(ABS(SUM([Profit])))), 3)
 ELSE 
     IF SUM([Profit]) < 0 THEN "-" ELSE "" END
     + "$"
     + LEFT(STR(ABS(SUM([Profit]))), 3)
 END

For more information about strings, see String Functions in Tableau Help.

Risorse aggiuntive

Type Conversion
Date Functions
 
Numero articolo Knowledge

001473689

 
Caricamento
Salesforce Help | Article