Forum Discussion
Anonymous
3 years agoNot applicable
Counting the rows in a category
Hello everyone, I'm trying to create a calculated column where I count the numer of consecutive weeks that an employee is in a determined quartile. It should be a DAX calculated column. To take into ...
- 3 years ago
Hi Anonymous ,
you can modify the measure like so:WeeksInQuartile = VAR __previousWeek = 'Table'[id_week] - 1 VAR __Result = RANKX ( FILTER( 'Table', 'Table'[id_employee] = EARLIER('Table'[id_employee]) && 'Table'[quartile] = EARLIER('Table'[quartile]) && 'Table'[quartile] = CALCULATE(MAX('Table'[quartile]), FILTER(all('Table'), 'Table'[id_week] = __previousWeek)) ), 'Table'[id_week], 'Table'[id_week], ASC ) Return __Result - 3 years ago
Hello Anonymous ,
thanks for taking the time to point out the error in the previous formula.
Please try out this new approach:WeeksInQuartile = VAR __StartRangeWeek = MAXX ( FILTER ( 'Table', 'Table'[id_employee] = EARLIER ( 'Table'[id_employee] ) && 'Table'[id_week] <= EARLIER ( 'Table'[id_week] ) && 'Table'[quartile] <> EARLIER ( 'Table'[quartile] ) ), 'Table'[id_week] ) VAR __EndRangeWeek = MINX ( FILTER ( 'Table', 'Table'[id_employee] = EARLIER ( 'Table'[id_employee] ) && 'Table'[id_week] >= EARLIER ( 'Table'[id_week] ) && 'Table'[quartile] <> EARLIER ( 'Table'[quartile] ) ), 'Table'[id_week] ) VAR __Result = RANKX ( FILTER ( 'Table', 'Table'[id_employee] = EARLIER ( 'Table'[id_employee] ) && 'Table'[quartile] = EARLIER ( 'Table'[quartile] ) && 'Table'[id_week] > __StartRangeWeek && 'Table'[id_week] < IF ( __EndRangeWeek = BLANK (), EARLIER ( 'Table'[id_week] ) + 1, __EndRangeWeek ) ), 'Table'[id_week], 'Table'[id_week], ASC ) RETURN __ResultPerformance will probably be terrible on large datasets.
A Power Query solution would probably be much faster in this case.
Anonymous
3 years agoNot applicable
Hi Anonymous ,
Please check the last reply from ImkeF , that can achieve your requirement. Could you please mark her post as Answered if it is OK? It will help the others in the community find the solution easily if they face the same problem as yours. Thank you.
Hi @aguuzdo ,
you can modify the measure like so:WeeksInQuartile = VAR __previousWeek = 'Table'[id_week] - 1 VAR __Result = RANKX ( FILTER( 'Table', 'Table'[id_employee] = EARLIER('Table'[id_employee]) && 'Table'[quartile] = EARLIER('Table'[quartile]) && 'Table'[quartile] = CALCULATE(MAX('Table'[quartile]), FILTER(all('Table'), 'Table'[id_week] = __previousWeek)) ), 'Table'[id_week], 'Table'[id_week], ASC ) Return __Result
Best Regards
Anonymous
3 years agoNot applicable
Hi. It isnt't working fine:
Thanks