Forum Discussion
Count Column by Group and filter Part 2.
I am posting a new thread because when I reply with a question about a possible solution, it is removed for Spam.
I need to know how many times a project goes in and out the " Tech Review" phase. The possible soultion was provided in a previous thread which i have posted below.
How many times =
VAR _maxIndexOf_ProjectAndStage =
MAXX (
FILTER (
'Table',
'Table'[ProjectId] = EARLIER ( 'Table'[ProjectId] )
&& 'Table'[Stage_Name] = "Tech Review"
),
'Table'[ProjectIndex]
)
VAR _maxIndexOfProject =
MAXX (
FILTER ( 'Table', 'Table'[ProjectId] = EARLIER ( 'Table'[ProjectId] ) ),
'Table'[ProjectIndex]
)
VAR _countNotTechReview =
COUNTROWS (
FILTER (
'Table',
'Table'[ProjectId] = EARLIER ( 'Table'[ProjectId] )
&& 'Table'[ProjectIndex] > EARLIER ( 'Table'[ProjectIndex] )
&& 'Table'[Stage_Name] <> "Tech Review"
)
)
RETURN
IF (
'Table'[Stage_Name] = "Tech Review",
_countNotTechReview - ( _maxIndexOfProject - _maxIndexOf_ProjectAndStage - 1 )
Below is the table results from the logic above. As you can see, it skips values in the "how many times" column. I think this is really close but I cannot figure out the last step. Thank you!
| Project ID | Stage Id | Created | Stage_Name | Index | How many times "Tech Review" |
| 690 | 1139 | 4/21/22 | Prod Files | 1 | |
| 690 | 1031 | 4/20/22 | Tech Review | 2 | 9 |
| 690 | 1086 | 4/19/22 | Revised Proof | 3 | |
| 690 | 1140 | 4/14/22 | Revised Proof | 4 | |
| 690 | 1031 | 4/14/22 | Tech Review | 5 | 7 |
| 690 | 1086 | 2/22/22 | Revised Proof | 6 | |
| 690 | 1031 | 2/20/22 | Tech Review | 7 | 6 |
| 690 | 1022 | 2/17/22 | Graphics | 8 | |
| 690 | 1135 | 2/17/22 | Estimating | 9 | |
| 690 | 1031 | 1/28/22 | Tech Review | 10 | 4 |
| 690 | 1031 | 1/28/22 | Tech Review | 11 | 4 |
| 690 | 1023 | 1/28/22 | 1st proof | 12 | |
| 690 | 1047 | 1/27/22 | In Production | 13 | |
| 690 | 1022 | 1/27/22 | Graphics | 14 | |
| 690 | 1031 | 1/27/22 | Tech Review | 15 | 1 |
| 1143 | 1086 | 4/21/22 | Revised Proof | 1 | |
| 1143 | 1024 | 4/21/22 | Revised Proof | 2 | |
| 1143 | 1135 | 4/19/22 | Estimating | 3 | |
| 1143 | 1086 | 4/18/22 | Revised Proof | 4 | |
| 1143 | 1024 | 4/18/22 | Revised Proof | 5 | |
| 1143 | 1022 | 4/18/22 | Graphics | 6 | |
| 1143 | 1031 | 4/18/22 | Tech Review | 7 | 17 |
| 1143 | 1140 | 4/12/22 | Revised Proof | 8 | |
| 1143 | 1031 | 4/12/22 | Tech Review | 9 | 16 |
| 1143 | 1086 | 4/11/22 | Revised Proof | 10 | |
| 1143 | 1024 | 4/11/22 | Revised Proof | 11 | |
| 1143 | 1031 | 4/8/22 | Tech Review | 12 | 14 |
| 1143 | 1022 | 4/7/22 | Graphics | 13 | |
| 1143 | 1031 | 3/29/22 | Tech Review | 14 | 13 |
| 1143 | 1086 | 3/29/22 | Revised Proof | 15 | |
| 1143 | 1024 | 3/29/22 | Revised Proof | 16 | |
| 1143 | 1086 | 3/28/22 | Revised Proof | 17 | |
| 1143 | 1031 | 3/23/22 | Tech Review | 18 | 10 |
| 1143 | 1022 | 3/22/22 | Graphics | 19 | |
| 1143 | 1086 | 3/15/22 | Revised Proof | 20 | |
| 1143 | 1023 | 3/15/22 | 1st proof | 21 | |
| 1143 | 1031 | 3/7/22 | Tech Review | 22 | 7 |
| 1143 | 1022 | 3/4/22 | Graphics | 23 | |
| 1143 | 1086 | 3/3/22 | Revised Proof | 24 | |
| 1143 | 1024 | 3/3/22 | Revised Proof | 25 | |
| 1143 | 1086 | 3/2/22 | Revised Proof | 26 | |
| 1143 | 1031 | 3/2/22 | Tech Review | 27 | 3 |
| 1143 | 1031 | 2/28/22 | Tech Review | 28 | 3 |
| 1143 | 1021 | 2/24/22 | Graphics | 29 | |
| 1143 | 1031 | 2/2/22 | Tech Review | 30 | 2 |
| 1143 | 1031 | 2/2/22 | Tech Review | 31 | 2 |
| 1143 | 1031 | 2/2/22 | Tech Review | 32 | 2 |
| 1143 | 1124 | 2/1/22 | Estimating | 33 | |
| 1143 | 1031 | 1/28/22 | Tech Review | 34 | 1 |
| 1143 | 1031 | 1/21/22 | Tech Review | 35 | 1 |
| 1143 | 1136 | 1/20/22 | Sent To Client | 36 | |
| 1143 | 1124 | 1/20/22 | Estimating | 37 | |
| 416 | 1031 | 4/21/22 | Tech Review | 1 | 17 |
| 416 | 1022 | 4/20/22 | Graphics | 2 | |
| 416 | 1086 | 3/29/22 | Revised Proof | 3 | |
| 416 | 1022 | 3/29/22 | Graphics | 4 | |
| 416 | 1031 | 3/28/22 | Tech Review | 5 | 14 |
| 416 | 1022 | 3/25/22 | Graphics | 6 | |
| 416 | 1031 | 3/21/22 | Tech Review | 7 | 13 |
| 416 | 1086 | 3/21/22 | Revised Proof | 8 | |
| 416 | 1031 | 3/21/22 | Tech Review | 9 | 12 |
| 416 | 1086 | 3/21/22 | Revised Proof | 10 | |
| 416 | 1024 | 3/21/22 | Revised Proof | 11 | |
| 416 | 1021 | 3/18/22 | Graphics | 12 | |
| 416 | 1021 | 3/17/22 | Graphics | 13 | |
| 416 | 1021 | 3/15/22 | Graphics | 14 | |
| 416 | 1135 | 3/11/22 | Estimating | 15 | |
| 416 | 1086 | 3/9/22 | Revised Proof | 16 | |
| 416 | 1031 | 3/3/22 | Tech Review | 17 | 5 |
| 416 | 1024 | 3/1/22 | Revised Proof | 18 | |
| 416 | 1135 | 3/1/22 | Estimating | 19 | |
| 416 | 1031 | 2/4/22 | Tech Review | 20 | 3 |
| 416 | 1031 | 2/3/22 | Tech Review | 21 | 3 |
| 416 | 1031 | 2/3/22 | Tech Review | 22 | 3 |
| 416 | 1031 | 2/2/22 | Tech Review | 23 | 3 |
| 416 | 1031 | 2/1/22 | Tech Review | 24 | 3 |
| 416 | 1031 | 2/1/22 | Tech Review | 25 | 3 |
| 416 | 1031 | 2/1/22 | Tech Review | 26 | 3 |
| 416 | 1031 | 1/28/22 | Tech Review | 27 | 3 |
| 416 | 1031 | 1/25/22 | Tech Review | 28 | 3 |
| 416 | 1031 | 1/18/22 | Tech Review | 29 | 3 |
| 416 | 1031 | 1/17/22 | Tech Review | 30 | 3 |
| 416 | 1031 | 12/17/21 | Tech Review | 31 | 3 |
| 416 | 1031 | 12/8/21 | Tech Review | 32 | 3 |
| 416 | 1022 | 12/7/21 | Graphics | 33 | |
| 416 | 1031 | 12/3/21 | Tech Review | 34 | 2 |
| 416 | 1061 | 12/3/21 | Graphics | 35 | |
| 416 | 1031 | 12/2/21 | Tech Review | 36 | 1 |
| 416 | 1031 | 11/23/21 | Tech Review | 37 | 1 |
| 416 | 1133 | 11/22/21 | Follow up | 38 | |
| 416 | 1138 | 11/22/21 | Scheduling | 39 | |
| 416 | 1113 | 11/18/21 | Clarification | 40 | |
| 416 | 1021 | 11/17/21 | Graphics | 41 |
Ah, I understand what you mean now.
This requires rather different logic we need to incorporate the concept of adjacent rows using the index.
Try this:
New Many = VAR _CurrPID = 'Table'[Project ID] VAR _CurrIndex = 'Table'[Index] VAR _CurrName = 'Table'[Stage_Name] VAR _SubTable_ = FILTER ( 'Table', 'Table'[Project ID] = _CurrPID && 'Table'[Index] >= _CurrIndex && 'Table'[Stage_Name] = "Tech Review" ) RETURN COUNTROWS ( FILTER ( _SubTable_, VAR _NextName = LOOKUPVALUE ( 'Table'[Stage_Name], 'Table'[Project ID], _CurrPID, 'Table'[Index], 'Table'[Index] + 1 ) RETURN _CurrName = "Tech Review" && _NextName <> "Tech Review" ) )
6 Replies
- AlexisOlsonSuper User
I'm not sure what you mean by "skipping". What result are you expecting instead?
- AnonymousNot applicable
I am looking for the data to read like the table below. That way I can see the Max(How Many Times) which will tell me how many times a project went in and out of the Tech Review phase.
Project ID Stage Id Created Stage_Name Index How many times "Tech Review" 690 1139 4/21/2022 Prod Files 1 690 1031 4/20/2022 Tech Review 2 5 690 1086 4/19/2022 Revised Proof 3 690 1140 4/14/2022 Revised Proof 4 690 1031 4/14/2022 Tech Review 5 4 690 1086 2/22/2022 Revised Proof 6 690 1031 2/20/2022 Tech Review 7 3 690 1022 2/17/2022 Graphics 8 690 1135 2/17/2022 Estimating 9 690 1031 1/28/2022 Tech Review 10 2 690 1031 1/28/2022 Tech Review 11 2 690 1023 1/28/2022 1st proof 12 690 1047 1/27/2022 In Production 13 690 1022 1/27/2022 Graphics 14 690 1031 1/27/2022 Tech Review 15 1 1143 1086 4/21/2022 Revised Proof 1 1143 1024 4/21/2022 Revised Proof 2 1143 1135 4/19/2022 Estimating 3 1143 1086 4/18/2022 Revised Proof 4 1143 1024 4/18/2022 Revised Proof 5 1143 1022 4/18/2022 Graphics 6 1143 1031 4/18/2022 Tech Review 7 9 1143 1140 4/12/2022 Revised Proof 8 1143 1031 4/12/2022 Tech Review 9 8 1143 1086 4/11/2022 Revised Proof 10 1143 1024 4/11/2022 Revised Proof 11 1143 1031 4/8/2022 Tech Review 12 7 1143 1022 4/7/2022 Graphics 13 1143 1031 3/29/2022 Tech Review 14 6 1143 1086 3/29/2022 Revised Proof 15 1143 1024 3/29/2022 Revised Proof 16 1143 1086 3/28/2022 Revised Proof 17 1143 1031 3/23/2022 Tech Review 18 5 1143 1022 3/22/2022 Graphics 19 1143 1086 3/15/2022 Revised Proof 20 1143 1023 3/15/2022 1st proof 21 1143 1031 3/7/2022 Tech Review 22 4 1143 1022 3/4/2022 Graphics 23 1143 1086 3/3/2022 Revised Proof 24 1143 1024 3/3/2022 Revised Proof 25 1143 1086 3/2/2022 Revised Proof 26 1143 1031 3/2/2022 Tech Review 27 3 1143 1031 2/28/2022 Tech Review 28 3 1143 1021 2/24/2022 Graphics 29 1143 1031 2/2/2022 Tech Review 30 2 1143 1031 2/2/2022 Tech Review 31 2 1143 1031 2/2/2022 Tech Review 32 2 1143 1124 2/1/2022 Estimating 33 1143 1031 1/28/2022 Tech Review 34 1 1143 1031 1/21/2022 Tech Review 35 1 1143 1136 1/20/2022 Sent To Client 36 1143 1124 1/20/2022 Estimating 37 416 1031 4/21/2022 Tech Review 1 8 416 1022 4/20/2022 Graphics 2 416 1086 3/29/2022 Revised Proof 3 416 1022 3/29/2022 Graphics 4 416 1031 3/28/2022 Tech Review 5 7 416 1022 3/25/2022 Graphics 6 416 1031 3/21/2022 Tech Review 7 6 416 1086 3/21/2022 Revised Proof 8 416 1031 3/21/2022 Tech Review 9 5 416 1086 3/21/2022 Revised Proof 10 416 1024 3/21/2022 Revised Proof 11 416 1021 3/18/2022 Graphics 12 416 1021 3/17/2022 Graphics 13 416 1021 3/15/2022 Graphics 14 416 1135 3/11/2022 Estimating 15 416 1086 3/9/2022 Revised Proof 16 416 1031 3/3/2022 Tech Review 17 4 416 1024 3/1/2022 Revised Proof 18 416 1135 3/1/2022 Estimating 19 416 1031 2/4/2022 Tech Review 20 3 416 1031 2/3/2022 Tech Review 21 3 416 1031 2/3/2022 Tech Review 22 3 416 1031 2/2/2022 Tech Review 23 3 416 1031 2/1/2022 Tech Review 24 3 416 1031 2/1/2022 Tech Review 25 3 416 1031 2/1/2022 Tech Review 26 3 416 1031 1/28/2022 Tech Review 27 3 416 1031 1/25/2022 Tech Review 28 3 416 1031 1/18/2022 Tech Review 29 3 416 1031 1/17/2022 Tech Review 30 3 416 1031 12/17/2021 Tech Review 31 3 416 1031 12/8/2021 Tech Review 32 3 416 1022 12/7/2021 Graphics 33 416 1031 12/3/2021 Tech Review 34 2 416 1061 12/3/2021 Graphics 35 416 1031 12/2/2021 Tech Review 36 1 416 1031 11/23/2021 Tech Review 37 1 416 1133 11/22/2021 Follow up 38 416 1138 11/22/2021 Scheduling 39 416 1113 11/18/2021 Clarification 40 416 1021 11/17/2021 Graphics 41 - AlexisOlsonSuper User
Ah, I understand what you mean now.
This requires rather different logic we need to incorporate the concept of adjacent rows using the index.
Try this:
New Many = VAR _CurrPID = 'Table'[Project ID] VAR _CurrIndex = 'Table'[Index] VAR _CurrName = 'Table'[Stage_Name] VAR _SubTable_ = FILTER ( 'Table', 'Table'[Project ID] = _CurrPID && 'Table'[Index] >= _CurrIndex && 'Table'[Stage_Name] = "Tech Review" ) RETURN COUNTROWS ( FILTER ( _SubTable_, VAR _NextName = LOOKUPVALUE ( 'Table'[Stage_Name], 'Table'[Project ID], _CurrPID, 'Table'[Index], 'Table'[Index] + 1 ) RETURN _CurrName = "Tech Review" && _NextName <> "Tech Review" ) )