-
1. Re: Calculation by attribute
Don Wise Apr 11, 2019 4:39 PM (in response to Salma Mirza)Hello Salma,
You'll get more and better responses with some fake/mock data in an actual Tableau Workbook.
Best, Don
-
2. Re: Calculation by attribute
Salma Mirza Apr 12, 2019 10:50 AM (in response to Don Wise)Thank you Don,
I'm attaching a twbx file and elaborating a little more.
1. My dataset has a dimension, Year (Fall 2017, Fall 2018, Fall 2019). I know, it should be a date field when I call it year, but its a text field because I am specifying it based on seasons.
2. I want to create a calculation Yield by each year (basically seeing how many customer out of all the 32 that we reached out to, made a purchase; see Yield calculated field in the twbx file )
3. I want a table that shows Yield by Year. Up until this point it is easy
4. This is the main question; If the Yield Fall 2019 is less than Yield in Fall 2018, I want it's font to be red, if not, then blue.
I've experimented with If statements in the calc field (If Year = Fall 2019, then "calculated Yield....) and then pulling it in into Color Mark, but it tells me that i cannot combine aggregate and non-aggregate functions.
I would really appreciate your help.
thanks
-
ConditionalFormattingTest.twbx 17.6 KB
-
-
3. Re: Calculation by attribute
Don Wise Apr 12, 2019 6:48 PM (in response to Salma Mirza)Hi Salma,
There's a couple of methods in this workbook. Hope it helps. Best, Don
Method 1 uses PREVIOUS_VALUE to look backwards one row (Fall 2018):
Method 2 uses the normal Quick Calculation to LOOKUP the previous row and determine if it's less than 0 then it's below otherwise it's above. FIRST() allows you to change the color for Fall 2017. If you don't want that, then simply remove the FIRST() clause.
1 of 1 people found this helpful-
ConditionalFormattingTest.twbx 21.2 KB
-
-
4. Re: Calculation by attribute
Salma Mirza Apr 15, 2019 1:14 PM (in response to Don Wise)Thank you Don,
This really helps. I used the 2nd method and color-coded it and it works. I modified the formula to specify that if Fall 2019 Yield is 0.5 less than Fall 2018, it should be red.
IF FIRST()=0 THEN 'first year' ELSEIF
LOOKUP(ZN([Yield]), -1)-ZN([Yield]) >0.5 THEN 'Below' ELSE 'Above' END
I am trying to refine it further because essentially I am only concerned with Fall 2019 falling below Fall 2018. I'm not bothered if the Fall 2018 Yield is less than Fall 2017 as its old news. I tried the following modification in the calculation. Does it seem like its working?
IF FIRST()=0 THEN 'first year'
ELSEIF First ()=-1 then 'second year'
ELSEIF First ()=-2
And LOOKUP(ZN([Yield]), -1)-ZN([Yield]) >0.5 THEN 'Below' ELSE 'Above' END
Thank you so much for your help
Salma
-
ConditionalFormattingTest2.twbx 27.1 KB
-
-
-
6. Re: Calculation by attribute
Salma Mirza Apr 16, 2019 10:44 AM (in response to Don Wise)This is really helpful Don. Thank you very much.
There's an additional piece to this (pls do let me know if I should't continue here and instead open a new question. I'm putting it here because it is related).
If we have further groupings besides "Year" , say "Industry", how can I apply the same conditional formatting. Essentially, I want to compare Fall 2019, Industry 3 Yield with Fall 2018, Industry 3 Yield, and if the Fall 2019 is less than Fall 2018, I want the Yield value to be turned red. I would like to replicate it for Industry 1 and 2. I used the existing color calc field and it seems to be comparing Fall 2017 Industry 3 with Fall 2017 Industry 3.
Thank you
-
ConditionalFormattingTest2.twbx 38.2 KB
-
-
7. Re: Calculation by attribute
Don Wise Apr 17, 2019 9:01 AM (in response to Salma Mirza)1 of 1 people found this helpfulHi Salma,
In that case, then you'd lose 'First Year' and 'Second Year' as those values would conflict with what you're trying to do. The calculation also needs to be changed and is more simplified to what it was before. However, requires the setting of Table Calc settings to work. Please see the screenshot below. Right-click the Color Table Calc and select Edit Table Calc. Then set the settings as shown in the screenshot, or in the attached. As this is an added question, if you'd mark it as helpful? Best, Don





