简体   繁体   中英

What is the excel equivalent of a COUNTIF with WILDCARD formula in Tableau?

I'm working on a Tableau table where I'd like to:

  1. Isolate specific string records in a dimension; then
  2. Count the instances that a specific string appears in that dimension (so all the records). A record may have multiple but different texts within.

Let's say my Dimension is called "Person Type" and I have 5 records with these respective values: Employee, Visitor, Employee; Visitor, Applicant, Visitor; Applicant

I understand that I could first create a filter on the dimension to only show the singular record types: Employee, Visitor, Applicant, but where I'm having trouble is creating a calculation that looks at all the records and counts the instances that the word "Employee" is present in and so forth. In excel, a COUNTIF formula with a text wildcard handles this.

Here's an excel screenshot of what I'm trying to accomplish.

Screenshot

Edit: Tried a calculation that was pretty close to the solution. For some reason it's not counting Applicant, when there's clearly two instances of it. anyone have any idea's on how to improve the calculation?

    IF CONTAINS([Person Types],'Employee') THEN "Employee"

ELSEIF CONTAINS([Person Types],'Visitor') THEN "Visitor"

ELSEIF CONTAINS([Person Types],'Applicant') THEN "Applicant"
END

result issue

You can use the Contains function in your LOD which operates like a wild card *X* in Excel.

So something like:

{ FIXED [NEWFIELD]: SUM(INT(CONTAINS([PERSON],"Employee"))) }

The code

    IF CONTAINS([Person Types],'Employee') THEN "Employee"

ELSEIF CONTAINS([Person Types],'Visitor') THEN "Visitor"

ELSEIF CONTAINS([Person Types],'Applicant') THEN "Applicant"
END

will not correctly count "Applicant" if there is an "Employee" or a "Visitor" since they will take precedence (each if is tested in sequence). So for example "Visitor; Applicant" will return "Visitor"

Also CONTAINS is case-sensitive so you might want to convert to all upper case to ensure that any subtle case variances are matched.

IF CONTAINS(UPPER([Person Types]),"APPLICANT") THEN "Applicant"

I recreated a sample like you have shown in your screenshot for a demonstration (it is always advised to copy and paste some rows of data directly in the code)

Steps (Tableau Desktop) It is though easier in Prep-

  • In the data source pane after connecting your data, click a down arrow on the person type field and click split

  • Two new field will be automatically created (given that maximum person types in one record is 2) or more rows will be created. (It is highly advised to have Tableau Prep) In tableau prep you can directly PIVOT these fields. See method here . But pivoting on calculated fields is not there in Tableau Desktop

  • Union the data with itself n (=2 here in this case) number of times. See GIF for help

在此处输入图像描述

  • create a calculated field say person types (I added a s intentionally to differentiate) with the following calculation
// A single person_type for each row.
CASE [Table Name]
WHEN "Sheet1" THEN [Person Type - Split 1]
WHEN "Sheet11" THEN [Person Type - Split 2]
END

Excluding null values you can create your desired views

在此处输入图像描述

Needless to say that you have to change values of [table name] as per your case in the calculated field

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM