Forum Discussion
Calculated Column - RankX with Filter
Hi,
I have a table with the following that has date+time (ActivityStart), grade (Grade), and a concatenated field (StudentCourseStageUnit). I need to rank each identical StudentCourseStageUnit where Grade is ONLY 'S' or 'U' (and completely ignoring blank or 'I') ranked by ActivityStart.
I would like this as a calculated column.
Here's a simplistic example:
| ActivityStart | StudentCourseStageUnit | Grade | AttemptNumber |
| 2021-01-01 07:00 AM | RicCourse1Stage1Unit1 | U | 1 |
| 2021-01-02 01:00 PM | RicCourse1Stage1Unit1 | I | |
| 2021-01-03 09:00 AM | RicCourse1Stage1Unit1 | S | 2 |
| 2021-01-04 06:00 AM | JonCourse1Stage1Unit1 | ||
| 2021-01-05 03:00 PM | JonCourse1Stage1Unit1 | S | 1 |
| 2021-01-07 08:30 AM | JonCourse1Stage1Unit2 | S | 1 |
Here is a sample PBIX file:
https://drive.google.com/file/d/1yKoQ7_EjUUPXJjXlMjXzLPtwPjtCmabn/view?usp=sharing
Thanks!
Hi RicFischer
AttemptNumberCol = CALCULATE ( COUNT ( AttemptNumber[ActivityStart] ), AttemptNumber[ActivityStart] <= EARLIER ( AttemptNumber[ActivityStart] ), AttemptNumber[Grade] IN { "S", "U" }, ALLEXCEPT ( AttemptNumber, AttemptNumber[StudentCourseStageUnit] ) )Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
How long? Try this
Col = COUNTROWS ( FILTER ( ALL ( AttemptNumber[ActivityStart], AttemptNumber[Grade], AttemptNumber[StudentCourseStageUnit] ), AttemptNumber[StudentCourseStageUnit] = EARLIER ( AttemptNumber[StudentCourseStageUnit] ) && AttemptNumber[ActivityStart] <= EARLIER ( AttemptNumber[ActivityStart] ) && AttemptNumber[Grade] IN { "S", "U" } ) )Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
6 Replies
- AlBCommunity Champion
Hi RicFischer
AttemptNumberCol = CALCULATE ( COUNT ( AttemptNumber[ActivityStart] ), AttemptNumber[ActivityStart] <= EARLIER ( AttemptNumber[ActivityStart] ), AttemptNumber[Grade] IN { "S", "U" }, ALLEXCEPT ( AttemptNumber, AttemptNumber[StudentCourseStageUnit] ) )Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
- RicFischerHelper I
It worked on my sample data, but it's taking quite a while for it to work on my real data which has nearly 500,000 rows.
- AlBCommunity Champion
How long? Try this
Col = COUNTROWS ( FILTER ( ALL ( AttemptNumber[ActivityStart], AttemptNumber[Grade], AttemptNumber[StudentCourseStageUnit] ), AttemptNumber[StudentCourseStageUnit] = EARLIER ( AttemptNumber[StudentCourseStageUnit] ) && AttemptNumber[ActivityStart] <= EARLIER ( AttemptNumber[ActivityStart] ) && AttemptNumber[Grade] IN { "S", "U" } ) )Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
- AlBCommunity Champion
Looks good. I actually realized the other day that was initial check was missing and was surprised that it was working in all cases...
Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.