We have a few threads dealing with similar subjects which should help you with the issue:
I am struggling with this same problem. Every option I try, even following the same steps in the examples you listed above, I get the error "Argument to AVG (an aggregate function) is already and aggregation, and cannot be further aggregated." This is frustrating because I had it working at some point, and then I went into the book at a later date and it threw a bunch of errors and erased my calculated fields so I cannot go back and find what I ddi previously. Any suggestions?
Tableau is not a calculation oriented tool and not good at multiple layer calculation.
So, here is my approach with two tables. There might be some workaround with using two layers of table calculation, but should be pretty complicated.
datediff('day',lookup(attr([Order Date]),-1),attr([Order Date]))
[Date Diff Bucket]
if [Date Diff]=0 then "0"
elseif [Date Diff]<=10 then "1-10"
elseif [Date Diff]<=20 then "10-20"
elseif [Date Diff]<=30 then "20-30"
elseif [Date Diff]<=40 then "30-40"
elseif [Date Diff]<=50 then "40-50"
elseif [Date Diff]<=60 then "50-60"
elseif [Date Diff]<=70 then "60-70"
elseif [Date Diff]<=80 then "70-80"
elseif [Date Diff]<=90 then "80-90"
elseif [Date Diff]<=100 then "90-100"
elseif [Date Diff]>100 then "100-"
You can handle bucket as dimension in table2.
Date Diff SM 9.2.twbx 30.1 KB