Tableau技术求助:如何基于多列筛选创建单个计算字段
Hey there fellow Tableau newbie! No worries at all—this is a super common use case, and creating that calculated field is totally straightforward once you know the syntax. Let's walk through exactly how to do this based on different scenarios you might need:
First, let's clarify: you want to use the Time measure only when specific strings show up in your Event or Screen dimensions, right? Here are the most common solutions:
1. Match a Single Specific String (Contains or Exact)
Fuzzy Match (String appears anywhere in the dimension)
If you want to pull Time only when the Event column includes the word "Checkout" (even if it's part of a longer phrase like "Checkout Initiated"), use this:
IF CONTAINS([Event], "Checkout") THEN [Time] ELSE 0 END
Exact Match (Dimension equals the exact string)
If you need Event to be exactly "Checkout" (no extra text), swap to this:
IF [Event] = "Checkout" THEN [Time] ELSE NULL END
2. Match Multiple Specific Strings (Either one works)
Need to include Time for multiple Event values? Use OR for fuzzy matches:
IF CONTAINS([Event], "Checkout") OR CONTAINS([Event], "Payment") THEN [Time] ELSE 0 END
For exact matches across multiple values, IN is cleaner:
IF [Event] IN ("Checkout", "Payment", "Order Confirmed") THEN [Time] ELSE NULL END
3. Match Strings in Both Dimensions (Combine Conditions)
If you need both Screen and Event to meet specific criteria (e.g., Screen is "Cart Page" AND Event includes "Item Added"), chain the conditions with AND:
IF [Screen] = "Cart Page" AND CONTAINS([Event], "Item Added") THEN [Time] ELSE 0 END
- Use
CONTAINS()when you don't have the full exact string (great for messy event data!) - Returning
NULLwill make those values disappear from your visuals; returning0keeps them visible as zero—pick whichever fits your analysis - Don't forget to name your calculated field something descriptive, like "Time for Checkout Events" so you can find it easily later
内容的提问来源于stack exchange,提问作者Dee

