You are on page 1of 4

www.sastrainingindelhi.

com
+91 7303066379

Calculated fields

non aggregated-

It has output value for each row and is not dependant on filters or views

aggregated-
www.sastrainingindelhi.com
+91 7303066379

Quest: Find logic error in option 1 and 2

option 1, bonus=

if sale>100 then bonus 10

else if sale>1000 then bonus 50

else 2

option 2,, bonus=

if sale>1000 then bonus 50

else if sale>100 then bonus 10

else 2

Quest: Create Bonus column in Tableau as per above logic

if [Sales]>1000 then 50

ELSEIF [Sales]>100 then 10

ELSE 2

end

Make fields below using Character operations for each row

1. City_State: concatenated for City-Sate like Houston-Texas

2. Category-Productname : extract the first 7 charactres of product name and concatenate with
category- like Office Supplies-Avery 5

3. special char falg: If product name contains ',' then 1 else 0

4. Get start of month for each order date.

5. New York flag: if state is 'New York' and segment is 'Home offlice' then 1

else state is 'New York' and segment is 'CONSUMER' then 2

else state is 'New York' and segment is 'corporate' then 3

for every other state 9


www.sastrainingindelhi.com
+91 7303066379

Date operations

6. weekday_val: get day of week from order date- like Monday, Tuesday etc.

7. Last3daysflag: last 3 days of month of order date then 1 else 0

8. Ship_date_new= get day of order date and month, year of ship date

9. next_Friday_Order_DT:

Import Return data attached and get following fields added in superstore data:-

10: order returned: get 1 where orders are returned

11. order returned charges : get return charges of orders are returned in ‘orders’ table

12. order returned charges Normal: get return charges of orders are returned in ‘orders’ table

Where shipment type= Normal

Solutions:

Bonus = IF('Sample - Superstore original file'[Sales]>1000, 50,10)

1. State_City = CONCATENATE(CONCATENATE('Sample - Superstore original file'[State], "-


"),'Sample - Superstore original file'[City])

2. Category_Product Name = CONCATENATE(CONCATENATE(MID('Sample - Superstore


original file'[Product Name],1,7),"-"),'Sample - Superstore original file'[Category])

3. Special Character flag = IF( FIND(",",'Sample - Superstore original file'[Product Name],1,0)=


0, 0, 1)

4. Month of orderdate = STARTOFMONTH('Sample - Superstore original file'[Order


Date].[Date])
5. Try yourself

6. weekday = WEEKDAY('Sample - Superstore original file'[Order Date],1)

7. Last3daysflag: = if ('Sample - Superstore original file'[Order Date]>= EOMONTH('Sample -


Superstore original file'[Order Date],0)-3, 1,0)
www.sastrainingindelhi.com
+91 7303066379

8. Below is example of NextSundaydate so that you can try Next Friday date yourself

SundayDate = if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 1 , 'Sample -


Superstore original file'[Order Date]

,if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 2 , 'Sample - Superstore original


file'[Order Date] +6

,if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 3 , 'Sample - Superstore original


file'[Order Date] +5

,if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 4 , 'Sample - Superstore original


file'[Order Date] +4

,if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 5 , 'Sample - Superstore original


file'[Order Date] +3

,if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 6 , 'Sample - Superstore original


file'[Order Date] +2

,if (WEEKDAY('Sample - Superstore original file'[Order Date],1)= 7 , 'Sample - Superstore original


file'[Order Date] +1

)))))))

For Return data try this below:

Make the relation and filter direction both sides

1. order returned = CALCULATE(COUNT('Sample - Superstore returns'[Returned]))


2. order returned charges = CALCULATE(SUM('Sample - Superstore returns'[Return Charge ]))
3. order returned charges Normal= CALCULATE(SUM('Sample - Superstore returns'[Return
Charge ]), FILTER('Sample - Superstore returns','Sample - Superstore returns'[Retun
Shipment ]="Normal"))

You might also like