简体   繁体   中英

How to count consecutive statuses in tableau?

I have a list of a equipment and its statuses. I want the count of consecutive statuses.

Equipment WO   Date.       Status
A.        101. 01/jan/2021 Pass
A.        102. 01/feb/2021 Pass
A.        103. 01/mar/2021 Fail
A.        104. 01/apr/2021 Fail
A.        105. 01/may/2021 Fail
A.        106. 01/jun/2021 Pass

Expected output

Consecutive Statuses 
2
2
3
3
3
1

Is it somehow possible?

There are two kinds of calculations that can take into account the ordering of data records: table calcs and SQL analytic (aka windowing) queries. Table calcs are performed on the client side - ie by Tableau upon the (aggregated) query results returned by the data source. SQL analytic queries are performed on the server side - ie by the database server. That fact has implications.

Both types of calculations require learning some details about how they work to use effectively. Both are useful but a little more complex than simple record level calculated fields. For table calcs, you'll have to learn about partitioning and addressing (aka compute using) and ordering. For this calculation, the PREVIOUS_VALUE() function may be valuable, but read the documentation and test on a simple case. That function is useful, but doesn't behave exactly the way most people assume from the name.

Since table calcs operate client side, they may not be the best choice if you you have very large data sets and would not otherwise need to fetch all data rows to the client side. In that case, invoking an analytic query with custom SQL might perform better.

LOD calculations are not the solution to problem where the order of data rows impacts the results.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM