5 Replies Latest reply on May 10, 2017 2:36 PM by John Healey

Simple Sum and Grouping by a Portion of Text

I have a table that has hours and then an itemcode. The itemcode is labeled like "/TCER" or "/TCAB" or "/SCTY" or "/SCASDF", etc. I want to be able to tell Tableau to find all the instances where it starts with "/TC" and to add all the hours up (and put it in a bar) then add up all the "/SC" beginning items and put that in a bar, and so on.

I need help! Beginner here so go easy please!

• 1. Re: Simple Sum and Grouping by a Portion of Text

Hey John,

Do your hours run directly into the text?

For example, "12/TCER" would be 12 hours with item code TCER?

I can help you out with this but to get it right I need to make sure how each hour/item code combo is structured.

Elliott Stam - InterWorks

• 2. Re: Simple Sum and Grouping by a Portion of Text

No, the hours are in a separate row. I put them in Tableau in Rows as a SUM([Hours]) so all I have to do is chop up the itemcode column into those sums.

• 3. Re: Simple Sum and Grouping by a Portion of Text

In that case, try this:

Calculated field - "TC Items" ...

IF CONTAINS( [item_code], '/TC')

THEN "TC Item"

ELSEIF CONTAINS( [item_code], '/SC')

THEN "SC Item"

END

You would now have a dimension that would chop your items into different bars in a worksheet, divided into two camps: one camp with items that started with /TC and another with items that started with /SC.

Hope that helps,

Elliott Stam - InterWorks

1 of 1 people found this helpful
• 4. Re: Simple Sum and Grouping by a Portion of Text

Another approach would be, Creating calculated field as

IF STARTSWITH([Item_Code],"/TC")=TRUE THEN 'TC Item'

ELSEIF STARTSWITH([Item_Code],"/SC")=TRUE THEN 'SC Item'

ELSE

NULL

END

• 5. Re: Simple Sum and Grouping by a Portion of Text

Wow! Thanks! I learned a lot! (Like, it doesn't go at the top but on the left creating a new calculation.) Now that I know that, it shouldn't be too difficult to noodle once I learn some syntax!