7 Replies Latest reply on Nov 26, 2018 8:39 AM by Norbert Maijoor

# Count the number of records based on another TC

Hi everyone!

I am new to Tableau and trying to figure out how to count the number of records based on another table calculation.

Here's a screenshot:

The second column is a calculated field which is the difference of the timestamp of the current row and that of next row (in seconds). I want to count how many rows meet the condition that

[time_diff]=-1 or [time_diff]>=180

But I got this error when I use SUM()

I have been struggling this for long. Any insight will be helpful!

Thanks,

Yinglu

• ###### 1. Re: Count the number of records based on another TC

Hi Yinglu,

I'm not 100% sure of your requirements, but if you want a count of number of records, then change your calculation to;

if [time diff]=-1 or [time diff] >=1800

then count([number or records])

end

HTH

Peter

• ###### 2. Re: Count the number of records based on another TC

Hi Yinglu,

Not sure what you are aiming exactly for but find my approach as reference below and stored in attached workbook version 2018.2 located in the original thread.

1. M1. lookup Time: lookup(attr([Time]),-1)

2. M2. Total visit: if [time_diff]=-1 or [time_diff]>=1800 then 1 else 0 END

Hope it helps,

Regards,

Norbert

• ###### 3. Re: Count the number of records based on another TC

Hi Peter,

What I am trying to achieve here is, if there are 2 records that [time_diff]=-1 and 2 records that [time_diff]> 1800, the number I get should be 2+2=4.

• ###### 4. Re: Count the number of records based on another TC

Hi Norbert,

Thanks for the attachment. This is close to what I want, but my final goal is to sum all the values in "Total Visit along Table Cell" (the last column in your attachment).

• ###### 5. Re: Count the number of records based on another TC

Hi Yinglu,

Not very sophisticated but could be an option:

1. Grand Total Visit: WINDOW_SUM(([Total visit]))

Hope it helps,

Regards,

Norbert

• ###### 6. Re: Count the number of records based on another TC

Hi Norbert,

Thanks for the solution!

Yinglu

• ###### 7. Re: Count the number of records based on another TC

Hi Yinglu,