Forum Discussion
Count Column by Group and filter
I posted before about a similar problem but I need to know how to handle multiple project.
I need to know how many times a project goes in and out the " Tech Review" phase. The solution for a table housing one project is below but I cant get it to account for multiple ProjectId/ProjectIndex.
How many times =
VAR _maxIndexOf_ProjectAndStage =
MAXX (
FILTER (
'Table',
'Table'[ProjectId] = EARLIER ( 'Table'[ProjectId] )
&& [Stage_Name] = "Tech Review"
),
[Index]
)
VAR _maxIndexOfProject =
MAXX (
FILTER ( 'Table', 'Table'[ProjectId] = EARLIER ( 'Table'[ProjectId] ) ),
[Index]
)
VAR _countNotTechReview =
COUNTROWS (
FILTER (
'Table',
[Index] > EARLIER ( 'Table'[Index] )
&& [Stage_Name] <> "Tech Review"
)
)
RETURN
IF (
[Stage_Name] = "Tech Review",
_countNotTechReview - ( _maxIndexOfProject - _maxIndexOf_ProjectAndStage - 1 )
)
Below is a snap show of the status table. Currently, all projects are housed in one large status table. Everytime an action occurs, a new line is created with a timestamp.
| ProjectId | StageId | Created | Stage_Name | ProjectIndex |
| 1 | 1031 | 2/10/2022 | Tech Review | 1 |
| 1 | 1031 | 2/10/2022 | Tech Review | 2 |
| 1 | 1047 | 2/10/2022 | Production | 3 |
| 1 | 1031 | 2/9/2022 | Tech Review | 4 |
| 1 | 1031 | 2/8/2022 | Tech Review | 5 |
| 1 | 1031 | 2/8/2022 | Tech Review | 6 |
| 1 | 1031 | 2/8/2022 | Tech Review | 7 |
| 1 | 1047 | 2/8/2022 | Production | 8 |
| 1 | 1031 | 2/3/2022 | Tech Review | 9 |
| 1 | 1023 | 2/3/2022 | Review Proof | 10 |
| 1 | 1031 | 2/2/2022 | Tech Review | 11 |
| 1 | 1031 | 2/2/2022 | Tech Review | 12 |
| 1 | 1022 | 1/28/2022 | Graphics | 13 |
| 1 | 1031 | 1/28/2022 | Tech Review | 14 |
| 1 | 1031 | 1/27/2022 | Tech Review | 15 |
| 1 | 1087 | 1/27/2022 | Review Proof | 16 |
| 1 | 1031 | 1/27/2022 | Tech Review | 17 |
| 1 | 1031 | 1/21/2022 | Tech Review | 18 |
| 1 | 1022 | 1/7/2022 | Graphics | 19 |
| 1 | 1128 | 12/1/2021 | Follow up Estimators | 20 |
| 1 | 1124 | 11/29/2021 | Estimating | 21 |
| 1 | 1124 | 11/10/2021 | Estimating | 22 |
| 2 | 1031 | 2/10/2022 | Tech Review | 1 |
| 2 | 1031 | 2/10/2022 | Tech Review | 2 |
| 2 | 1031 | 2/10/2022 | Tech Review | 3 |
| 2 | 1031 | 2/10/2022 | Tech Review | 4 |
| 2 | 1047 | 2/10/2022 | Production | 5 |
| 2 | 1031 | 2/9/2022 | Tech Review | 6 |
| 2 | 1031 | 2/8/2022 | Tech Review | 7 |
| 2 | 1031 | 2/8/2022 | Tech Review | 8 |
| 2 | 1022 | 1/7/2022 | Graphics | 9 |
| 3 | 1031 | 1/21/2022 | Tech Review | 1 |
| 3 | 1031 | 1/21/2022 | Tech Review | 2 |
| 3 | 1022 | 1/7/2022 | Graphics | 3 |
| 3 | 1031 | 1/21/2022 | Tech Review | 4 |
| 3 | 1022 | 1/7/2022 | Graphics | 5 |
| 3 | 1124 | 11/10/2021 | Estimating | 6 |
And i need the table to return this
| ProjectId | StageId | Created | Stage_Name | ProjectIndex | How many times "Tech Review" |
| 1 | 1031 | 2/10/2022 | Tech Review | 1 | 6 |
| 1 | 1031 | 2/10/2022 | Tech Review | 2 | 6 |
| 1 | 1047 | 2/10/2022 | Production | 3 | |
| 1 | 1031 | 2/9/2022 | Tech Review | 4 | 5 |
| 1 | 1031 | 2/8/2022 | Tech Review | 5 | 5 |
| 1 | 1031 | 2/8/2022 | Tech Review | 6 | 5 |
| 1 | 1031 | 2/8/2022 | Tech Review | 7 | 5 |
| 1 | 1047 | 2/8/2022 | Production | 8 | |
| 1 | 1031 | 2/3/2022 | Tech Review | 9 | 4 |
| 1 | 1023 | 2/3/2022 | Review Proof | 10 | |
| 1 | 1031 | 2/2/2022 | Tech Review | 11 | 3 |
| 1 | 1031 | 2/2/2022 | Tech Review | 12 | 3 |
| 1 | 1022 | 1/28/2022 | Graphics | 13 | |
| 1 | 1031 | 1/28/2022 | Tech Review | 14 | 2 |
| 1 | 1031 | 1/27/2022 | Tech Review | 15 | 2 |
| 1 | 1087 | 1/27/2022 | Review Proof | 16 | |
| 1 | 1031 | 1/27/2022 | Tech Review | 17 | 1 |
| 1 | 1031 | 1/21/2022 | Tech Review | 18 | 1 |
| 1 | 1022 | 1/7/2022 | Graphics | 19 | |
| 1 | 1128 | 12/1/2021 | Follow up Estimators | 20 | |
| 1 | 1124 | 11/29/2021 | Estimating | 21 | |
| 1 | 1124 | 11/10/2021 | Estimating | 22 | |
| 2 | 1031 | 2/10/2022 | Tech Review | 1 | 2 |
| 2 | 1031 | 2/10/2022 | Tech Review | 2 | 2 |
| 2 | 1031 | 2/10/2022 | Tech Review | 3 | 2 |
| 2 | 1031 | 2/10/2022 | Tech Review | 4 | 2 |
| 2 | 1047 | 2/10/2022 | Production | 5 | |
| 2 | 1031 | 2/9/2022 | Tech Review | 6 | 1 |
| 2 | 1031 | 2/8/2022 | Tech Review | 7 | 1 |
| 2 | 1031 | 2/8/2022 | Tech Review | 8 | 1 |
| 2 | 1022 | 1/7/2022 | Graphics | 9 | |
| 3 | 1031 | 1/21/2022 | Tech Review | 1 | 3 |
| 3 | 1031 | 1/21/2022 | Tech Review | 2 | 2 |
| 3 | 1022 | 1/7/2022 | Graphics | 3 | |
| 3 | 1031 | 1/21/2022 | Tech Review | 4 | 1 |
| 3 | 1022 | 1/7/2022 | Graphics | 5 | |
| 3 | 1124 | 11/10/2021 | Estimating | 6 |
7 Replies
- AlexisOlsonSuper User
You're very nearly there. All you need to do is add the condition inside the _countNotTechReview you have in the prior variables.
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 ) )- AnonymousNot applicable
Could you message me directly? I am trying to reply to your comment with an issue that is showing up but it keeps getting removed for spam for some reason.
- AnonymousNot applicable
AlexisOlson This is the table i get when i try your solution. It is skipping values in the "How many times" column
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 - v-chenwuz-msftCommunity Support
Hi Anonymous ,
I made some mistakes in previous post.
The index([Global index]) should be created of all project. And add one more filter on "_countNotTechReview"
var _countNotTechReview = COUNTROWS ( FILTER ( 'NewTable', [Global Index] > EARLIER ( 'NewTable'[Global Index] ) && [Global Index] <= _maxIndexOfProject // one more filter here && [Stage_Name] <> "Tech Review" ) )Pbix in the end you can refer.
Best Regards
Community Support Team _ chenwu zhu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Based on your adjustments, I am still getting off numbers. Below shows the count is still off with a glabal_index. AlexisOlson Tagging you on this as well since you also provided great feedback.
ProjectId StageId ActionsIndex.Created Stage_Name PorjectIndex How many times Global_Index 330 1031 2/10/22 Tech Review 1 -3 270 330 1031 2/10/22 Tech Review 2 -3 271 330 1031 2/10/22 Tech Review 3 -3 272 330 1031 2/10/22 Tech Review 4 -3 273 330 1047 2/10/22 In Production
(PM)5 274 330 1031 2/9/22 Tech Review 6 -3 275 330 1031 2/8/22 Tech Review 7 -3 276 330 1031 2/8/22 Tech Review 8 -3 277 330 1031 2/8/22 Tech Review 9 -3 278 330 1047 2/8/22 In Production
(PM)10 279 330 1031 2/4/22 Tech Review 11 -3 280 330 1023 2/3/22 1st proof 12 281 330 1031 2/3/22 Tech Review 13 -3 282 330 1031 2/3/22 Tech Review 14 -3 283 330 1031 2/2/22 Tech Review 15 -3 284 330 1031 2/2/22 Tech Review 16 -3 285 330 1022 1/28/22 Graphics 17 286 330 1031 1/28/22 Tech Review 18 -3 287 330 1031 1/27/22 Tech Review 19 -3 288 330 1031 1/27/22 Tech Review 20 -3 289 330 1031 1/27/22 Tech Review 21 -3 290 330 1031 1/27/22 Tech Review 22 -3 291 330 1087 1/27/22 Sent Proof To PM (Hosp) 23 292 330 1031 1/21/22 Tech Review 24 -3 293 330 1021 1/7/22 Graphics 25 294 330 1128 12/1/21 Estimating 26 295 330 1124 11/29/21 Estimating 27 296 330 1124 11/10/21 Estimating 28 297 416 1031 4/21/22 Tech Review 1 -3 525 416 1022 4/20/22 Graphics 2 526 416 1086 3/29/22 Revised Proof 3 527 416 1022 3/29/22 Graphics 4 528 416 1031 3/28/22 Tech Review 5 -3 529 416 1022 3/25/22 Graphics 6 530 416 1031 3/21/22 Tech Review 7 -3 531 416 1086 3/21/22 Revised Proof 8 532 416 1031 3/21/22 Tech Review 9 -3 533 416 1086 3/21/22 Revised Proof 10 534 416 1024 3/21/22 Revised Proof 11 535 416 1021 3/18/22 Graphics 12 536 416 1021 3/17/22 Graphics 13 537 416 1021 3/15/22 Graphics 14 538 416 1135 3/11/22 Estimating 15 539 416 1086 3/9/22 Revised Proof 16 540 416 1031 3/3/22 Tech Review 17 -3 541 416 1024 3/1/22 Revised Proof 18 542 416 1135 3/1/22 Estimating 19 543 416 1031 2/4/22 Tech Review 20 -3 544 416 1031 2/3/22 Tech Review 21 -3 545 416 1031 2/3/22 Tech Review 22 -3 546 416 1031 2/2/22 Tech Review 23 -3 547 416 1031 2/1/22 Tech Review 24 -3 548 416 1031 2/1/22 Tech Review 25 -3 549 416 1031 2/1/22 Tech Review 26 -3 550 416 1031 1/28/22 Tech Review 27 -3 551 416 1031 1/25/22 Tech Review 28 -3 552 416 1031 1/18/22 Tech Review 29 -3 553 416 1031 1/17/22 Tech Review 30 -3 554 416 1031 12/17/21 Tech Review 31 -3 555 416 1031 12/8/21 Tech Review 32 -3 556 416 1022 12/7/21 Graphics 33 557 416 1031 12/3/21 Tech Review 34 -3 558 416 1061 12/3/21 Graphics 35 559 416 1031 12/2/21 Tech Review 36 -3 560 416 1031 11/23/21 Tech Review 37 -3 561 416 1133 11/22/21 Follow up Maps-Evacs 38 562 416 1138 11/22/21 Sent to Scheduling 39 563 416 1113 11/18/21 Evac Clarification 40 564 416 1021 11/17/21 Graphics 41 565 1143 1021 4/26/22 Graphics 1 2907 1143 1086 4/21/22 Revised Proof 2 2908 1143 1024 4/21/22 Revised Proof 3 2909 1143 1135 4/19/22 Estimating 4 2910 1143 1086 4/18/22 Revised Proof 5 2911 1143 1024 4/18/22 Revised Proof 6 2912 1143 1022 4/18/22 Graphics 7 2913 1143 1031 4/18/22 Tech Review 8 -1 2914 1143 1140 4/12/22 Revised Proof 9 2915 1143 1031 4/12/22 Tech Review 10 -1 2916 1143 1086 4/11/22 Revised Proof 11 2917 1143 1024 4/11/22 Revised Proof 12 2918 1143 1031 4/8/22 Tech Review 13 -1 2919 1143 1022 4/7/22 Graphics 14 2920 1143 1031 3/29/22 Tech Review 15 -1 2921 1143 1086 3/29/22 Revised Proof 16 2922 1143 1024 3/29/22 Revised Proof 17 2923 1143 1086 3/28/22 Revised Proof 18 2924 1143 1031 3/23/22 Tech Review 19 -1 2925 1143 1022 3/22/22 Graphics 20 2926 1143 1086 3/15/22 Revised Proof 21 2927 1143 1023 3/15/22 1st proof 22 2928 1143 1031 3/7/22 Tech Review 23 -1 2929 1143 1022 3/4/22 Graphics 24 2930 1143 1086 3/3/22 Revised Proof 25 2931 1143 1024 3/3/22 Revised Proof 26 2932 1143 1086 3/2/22 Revised Proof 27 2933 1143 1031 3/2/22 Tech Review 28 -1 2934 1143 1031 2/28/22 Tech Review 29 -1 2935 1143 1021 2/24/22 Graphics 30 2936 1143 1031 2/2/22 Tech Review 31 -1 2937 1143 1031 2/2/22 Tech Review 32 -1 2938 1143 1031 2/2/22 Tech Review 33 -1 2939 1143 1124 2/1/22 Estimating 34 2940 1143 1031 1/28/22 Tech Review 35 -1 2941 1143 1031 1/21/22 Tech Review 36 -1 2942 1143 1032 1/20/22 PM-WIP 37 2943 1143 1124 1/20/22 Estimating 38 2944 - v-chenwuz-msftCommunity Support
Hi Anonymous ,
Please share your pbix file without sensitive data and cover all possible situations if you need more help.
Best Regards
Community Support Team _ chenwu zhu