March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I need helping automatically updating the FirstAttemptPass column in the table below. I'm afraid my brain is not wrapping itself around the logic needed to accomplish this. If we need to create additional columns, that's fine.
In this usage, a single test is comprised of matching Oral and Practical Test Types. While a Practical may not have a matching Oral (see Kay, Sue, and Ron, below), an Oral always leads to a Practical.
The grades are Satisfactory, Unsatisfactory, and Incomplete.
The protocol is:
I hope I've spelled out all the conditions. If not, please feel free to ask for clarification. I've linked a .pbix file which has the same data as the table inserted below.
Sample Data for FirstAttemptPass
StudentName | ActivityStart | Course | Stage | Unit | Test Type | Grade | FirstAttemptPass |
Ana | 01/02/21 8:00 AM | Course 1 | Stage 1 | Unit 10 | Oral | S | Yes |
Ana | 01/03/21 5:00 PM | Course 1 | Stage 1 | Unit 10 | Practical | S | Yes |
Ana | 01/04/21 5:00 PM | Course 1 | Stage 2 | Unit 17 | Oral | I | |
Ana | 01/06/21 1:00 PM | Course 1 | Stage 2 | Unit 17 | Oral | S | Yes |
Ana | 01/07/21 8:00 AM | Course 1 | Stage 2 | Unit 17 | Practical | S | Yes |
Deb | 01/01/21 8:00 PM | Course 2 | Stage 1 | Unit 12 | Oral | U | No |
Deb | 01/02/21 7:00 PM | Course 2 | Stage 1 | Unit 12 | Oral | S | No |
Deb | 01/04/21 3:00 PM | Course 2 | Stage 1 | Unit 12 | Practical | S | No |
Deb | 01/05/21 10:00 PM | Course 2 | Stage 2 | Unit 14 | Oral | S | Yes |
Deb | 01/06/21 7:00 PM | Course 2 | Stage 2 | Unit 14 | Practical | S | Yes |
Sam | 01/01/21 11:00 AM | Course 3 | Stage 1 | Unit 7 | Oral | I | |
Sam | 01/02/21 10:00 AM | Course 3 | Stage 1 | Unit 7 | Oral | U | No |
Sam | 01/03/21 7:00 PM | Course 3 | Stage 1 | Unit 7 | Oral | S | No |
Sam | 01/05/21 11:00 AM | Course 3 | Stage 1 | Unit 7 | Practical | S | No |
Tom | 01/01/21 10:00 AM | Course 1 | Stage 1 | Unit 10 | Oral | S | No |
Tom | 01/02/21 9:00 AM | Course 1 | Stage 1 | Unit 10 | Practical | I | |
Tom | 01/03/21 10:00 AM | Course 1 | Stage 1 | Unit 10 | Practical | U | No |
Tom | 01/05/21 7:00 AM | Course 2 | Stage 1 | Unit 9 | Oral | S | Yes |
Tom | 01/06/21 9:00 AM | Course 2 | Stage 1 | Unit 9 | Practical | I | |
Tom | 01/07/21 3:00 PM | Course 2 | Stage 1 | Unit 9 | Practical | S | Yes |
Kay | 01/12/21 8:30 AM | Course 4 | Stage 4 | Unit 4 | Practical | S | Yes |
Sue | 01/12/21 10:45 AM | Course 4 | Stage 4 | Unit 4 | Practical | I | |
Sue | 01/13/21 10:00 AM | Course 4 | Stage 4 | Unit 4 | Practical | S | Yes |
Ron | 01/14/21 2:30 PM | Course 4 | Stage 4 | Unit 4 | Practical | I | |
Ron | 01/15/21 3:00 PM | Course 4 | Stage 4 | Unit 4 | Practical | U | No |
Solved! Go to Solution.
@RicFischer
I think I solved it, please check.
FirstAttemptPass Solved =
VAR __o = "Oral"
VAR __p = "Practical"
VAR __grades =
CALCULATETABLE (
Table1,
ALLEXCEPT (
Table1,
Table1[StudentName],
Table1[Course],
Table1[Stage],
Table1[Unit]
)
)
VAR Result =
SWITCH (
TRUE (),
CONTAINS ( __grades, Table1[Test Type], __o, Table1[Grade], "U" )
|| CONTAINS ( __grades, Table1[Test Type], __p, Table1[Grade], "U" ), "NO",
CONTAINS ( __grades, Table1[Test Type], __o, Table1[Grade], "S" )
&& CONTAINS ( __grades, Table1[Test Type], __p, Table1[Grade], "S" ), "YES",
NOT CONTAINS ( __grades, Table1[Test Type], __o )
&& CONTAINS ( __grades, Table1[Test Type], __p, Table1[Grade], "S" ), "YES"
)
RETURN
IF ( Table1[Grade] = "I", BLANK (), IF ( Table1[Grade] = "U", "NO", Result ) )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@RicFischer
This could work:
FirstAttemptPass Solved =
VAR __o = "Oral"
VAR __p = "Practical"
VAR __grades =
CALCULATETABLE (
FirstAttemptPass,
ALLEXCEPT (
FirstAttemptPass,
FirstAttemptPass[StudentName],
FirstAttemptPass[Course],
FirstAttemptPass[Stage]
// FirstAttemptPass[Unit]
),
FirstAttemptPass[CancelReason] = BLANK()
)
VAR Result =
SWITCH (
TRUE (),
CONTAINS ( __grades, FirstAttemptPass[Test Type], __o, FirstAttemptPass[Grade], "U" )
|| CONTAINS ( __grades, FirstAttemptPass[Test Type], __p, FirstAttemptPass[Grade], "U" ), "NO",
CONTAINS ( __grades, FirstAttemptPass[Test Type], __o, FirstAttemptPass[Grade], "S" )
&& CONTAINS ( __grades, FirstAttemptPass[Test Type], __p, FirstAttemptPass[Grade], "S" ), "YES",
NOT CONTAINS ( __grades, FirstAttemptPass[Test Type], __o )
&& CONTAINS ( __grades, FirstAttemptPass[Test Type], __p, FirstAttemptPass[Grade], "S" ), "YES"
)
RETURN
SWITCH(
TRUE(),
FirstAttemptPass[Grade]= "I", BLANK(),
FirstAttemptPass[CancelReason] <> BLANK(), BLANK(),
FirstAttemptPass[Grade] = "U", "NO",
Result
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
When I plugged the answer into my Power BI, I realized I had forgotten my sample data was missing a few crucial fields (because, in my real data, the names of the units don't always match up between Oral and Practical). So, I'm asking for a second time in the hopes that you all will be kind enough to help me with this (again).
I forgot to mention in my first post that I needed a Column, not a measure.
The grades are Satisfactory, Unsatisfactory, and Incomplete.
The clarified protocol is:
The critical new item is the MatchingCourseStageUnit field. Because the names of the units don't always line up (an example: Unit 9a might be Oral and Unit 9b might be Practical) in the older, now-retired courses, I had to come up with a separate matching field for lookup sanity.
Sample Data (same link as before, but file is updated)
Here's my new sample data:
StudentName | ActivityStart | Course | Stage | Unit | CourseStageUnit | OppositeCourseStageUnit | MatchingCourseStageUnit | Test Type | Grade | ManualFirstAttemptPass |
Ana | 01/02/21 8:00 AM | Course 1 | Stage 1 | Unit 10 Oral | Course 1Stage 1Unit 10 Oral | Course 1Stage 1Unit 10 Practical | Course 1Stage 1Unit 10 Practical | Oral | S | Yes |
Tom | 01/01/21 10:00 AM | Course 1 | Stage 1 | Unit 10 Oral | Course 1Stage 1Unit 10 Oral | Course 1Stage 1Unit 10 Practical | Course 1Stage 1Unit 10 Practical | Oral | S | No |
Ana | 01/03/21 5:00 PM | Course 1 | Stage 1 | Unit 10 Practical | Course 1Stage 1Unit 10 Practical | Course 1Stage 1Unit 10 Oral | Course 1Stage 1Unit 10 Oral | Practical | S | Yes |
Tom | 01/02/21 9:00 AM | Course 1 | Stage 1 | Unit 10 Practical | Course 1Stage 1Unit 10 Practical | Course 1Stage 1Unit 10 Oral | Course 1Stage 1Unit 10 Oral | Practical | I | |
Tom | 01/03/21 10:00 AM | Course 1 | Stage 1 | Unit 10 Practical | Course 1Stage 1Unit 10 Practical | Course 1Stage 1Unit 10 Oral | Course 1Stage 1Unit 10 Oral | Practical | U | No |
Ana | 01/04/21 5:00 PM | Course 1 | Stage 2 | Unit 17 Oral | Course 1Stage 2Unit 17 Oral | Course 1Stage 2Unit 17 Practical | Course 1Stage 2Unit 17 Practical | Oral | I | |
Ana | 01/06/21 1:00 PM | Course 1 | Stage 2 | Unit 17 Oral | Course 1Stage 2Unit 17 Oral | Course 1Stage 2Unit 17 Practical | Course 1Stage 2Unit 17 Practical | Oral | S | Yes |
Ana | 01/07/21 8:00 AM | Course 1 | Stage 2 | Unit 17 Practical | Course 1Stage 2Unit 17 Practical | Course 1Stage 2Unit 17 Oral | Course 1Stage 2Unit 17 Oral | Practical | S | Yes |
Deb | 01/01/21 8:00 PM | Course 2 | Stage 1 | Unit 12 Oral | Course 2Stage 1Unit 12 Oral | Course 2Stage 1Unit 12 Practical | Course 2Stage 1Unit 12 Practical | Oral | U | No |
Deb | 01/02/21 7:00 PM | Course 2 | Stage 1 | Unit 12 Oral | Course 2Stage 1Unit 12 Oral | Course 2Stage 1Unit 12 Practical | Course 2Stage 1Unit 12 Practical | Oral | S | No |
Deb | 01/04/21 3:00 PM | Course 2 | Stage 1 | Unit 12 Practical | Course 2Stage 1Unit 12 Practical | Course 2Stage 1Unit 12 Oral | Course 2Stage 1Unit 12 Oral | Practical | S | No |
Tom | 01/05/21 7:00 AM | Course 2 | Stage 1 | Unit 9 Oral | Course 2Stage 1Unit 9 Oral | Course 2Stage 1Unit 9 Practical | Course 2Stage 1Unit 9 Practical | Oral | S | Yes |
Tom | 01/06/21 9:00 AM | Course 2 | Stage 1 | Unit 9 Practical | Course 2Stage 1Unit 9 Practical | Course 2Stage 1Unit 9 Oral | Course 2Stage 1Unit 9 Oral | Practical | I | |
Tom | 01/07/21 3:00 PM | Course 2 | Stage 1 | Unit 9 Practical | Course 2Stage 1Unit 9 Practical | Course 2Stage 1Unit 9 Oral | Course 2Stage 1Unit 9 Oral | Practical | S | Yes |
Deb | 01/05/21 10:00 PM | Course 2 | Stage 2 | Unit 14 Oral | Course 2Stage 2Unit 14 Oral | Course 2Stage 2Unit 14 Practical | Course 2Stage 2Unit 14 Practical | Oral | S | Yes |
Deb | 01/06/21 7:00 PM | Course 2 | Stage 2 | Unit 14 Practical | Course 2Stage 2Unit 14 Practical | Course 2Stage 2Unit 14 Oral | Course 2Stage 2Unit 14 Oral | Practical | S | Yes |
Sam | 01/01/21 11:00 AM | Course 3 | Stage 1 | Unit 7 Oral | Course 3Stage 1Unit 7 Oral | Course 3Stage 1Unit 7 Practical | Course 3Stage 1Unit 7 Practical | Oral | I | |
Sam | 01/02/21 10:00 AM | Course 3 | Stage 1 | Unit 7 Oral | Course 3Stage 1Unit 7 Oral | Course 3Stage 1Unit 7 Practical | Course 3Stage 1Unit 7 Practical | Oral | U | No |
Sam | 01/03/21 7:00 PM | Course 3 | Stage 1 | Unit 7 Oral | Course 3Stage 1Unit 7 Oral | Course 3Stage 1Unit 7 Practical | Course 3Stage 1Unit 7 Practical | Oral | S | No |
Sam | 01/05/21 11:00 AM | Course 3 | Stage 1 | Unit 7 Practical | Course 3Stage 1Unit 7 Practical | Course 3Stage 1Unit 7 Oral | Course 3Stage 1Unit 7 Oral | Practical | S | No |
Kay | 01/12/21 8:30 AM | Course 4 | Stage 4 | Unit 4 Practical | Course 4Stage 4Unit 4 Practical | Course 4Stage 4Unit 4 Oral | Practical | S | Yes | |
Sue | 01/12/21 10:45 AM | Course 4 | Stage 4 | Unit 4 Practical | Course 4Stage 4Unit 4 Practical | Course 4Stage 4Unit 4 Oral | Practical | I | ||
Sue | 01/13/21 10:00 AM | Course 4 | Stage 4 | Unit 4 Practical | Course 4Stage 4Unit 4 Practical | Course 4Stage 4Unit 4 Oral | Practical | S | Yes | |
Ron | 01/14/21 2:30 PM | Course 4 | Stage 4 | Unit 4 Practical | Course 4Stage 4Unit 4 Practical | Course 4Stage 4Unit 4 Oral | Practical | I | ||
Ron | 01/15/21 3:00 PM | Course 4 | Stage 4 | Unit 4 Practical | Course 4Stage 4Unit 4 Practical | Course 4Stage 4Unit 4 Oral | Practical | U | No |
If anybody can help with this, I would really appreciate it.
To be more specific, I need to modify @Fowmy's solution where it looks at a MatchingCourseStageUnit field to find the matching course (oral-to-practical or practical-to-oral) in order to determine if the entire event was a first-time-pass or not. For example:
In the first record, we have Ana's first Oral with a CourseStageUnit value of "Course 1Stage 1Unit 10 Oral". We see she passed it (Grade="S"), so we need to use the MatchingCourseStageUnit field with a value of "Course 1Stage 1Unit 10 Practical" to look up the matching unit. The matching unit would be with the same student name (Ana) and a CourseStageUnit value of "Course 1Stage 1Unit 10 Practical". If that's a Grade="S" (and it is in this case), then it's a Yes on the FirstAttemptPass calculation.
If it's a failure for either unit(Grade="U"), then both units need a "No" and all other attempts of both the Oral and Practical for the same Student, Course, and Stage need to be a "No" as well, because they didn't pass it on the first attempt.
@RicFischer
Can you try the solution that I already provided but remove the filter on the [Unit] within ALLEXCEPT.
as follows?
FirstAttemptPass Solved =
VAR __o = "Oral"
VAR __p = "Practical"
VAR __grades =
CALCULATETABLE (
Sheet1,
ALLEXCEPT (
Sheet1,
Sheet1[StudentName],
Sheet1[Course],
Sheet1[Stage]
// Sheet1[Unit]
)
)
VAR Result =
SWITCH (
TRUE (),
CONTAINS ( __grades, Sheet1[Test Type], __o, Sheet1[Grade], "U" )
|| CONTAINS ( __grades, Sheet1[Test Type], __p, Sheet1[Grade], "U" ), "NO",
CONTAINS ( __grades, Sheet1[Test Type], __o, Sheet1[Grade], "S" )
&& CONTAINS ( __grades, Sheet1[Test Type], __p, Sheet1[Grade], "S" ), "YES",
NOT CONTAINS ( __grades, Sheet1[Test Type], __o )
&& CONTAINS ( __grades, Sheet1[Test Type], __p, Sheet1[Grade], "S" ), "YES"
)
RETURN
IF ( Sheet1[Grade] = "I", BLANK (), IF ( Sheet1[Grade] = "U", "NO", Result ) )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
I'm getting some now that are FirstAttemptPass Solved with Yes even though it has no grade at all. No Grade is "(Blank)" in the drop-down for that field:
This happens when the event is canceled, something I didn't think of when posing the question. They should be completely ignored in this formula. They do not affect the status of a later attempt being considered as a First Attempt.
@RicFischer
Please share sample data with blank grades and the expected results .
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
File updated at original link: https://drive.google.com/file/d/1OfIkdM5DbmERBG7CDbZFSsFDYA71aszY/view?usp=sharing
Notes:
Thank you, again, for your help. I've been studying and learning from what you've already provided so I can do this on my own in the future.
@RicFischer
This could work:
FirstAttemptPass Solved =
VAR __o = "Oral"
VAR __p = "Practical"
VAR __grades =
CALCULATETABLE (
FirstAttemptPass,
ALLEXCEPT (
FirstAttemptPass,
FirstAttemptPass[StudentName],
FirstAttemptPass[Course],
FirstAttemptPass[Stage]
// FirstAttemptPass[Unit]
),
FirstAttemptPass[CancelReason] = BLANK()
)
VAR Result =
SWITCH (
TRUE (),
CONTAINS ( __grades, FirstAttemptPass[Test Type], __o, FirstAttemptPass[Grade], "U" )
|| CONTAINS ( __grades, FirstAttemptPass[Test Type], __p, FirstAttemptPass[Grade], "U" ), "NO",
CONTAINS ( __grades, FirstAttemptPass[Test Type], __o, FirstAttemptPass[Grade], "S" )
&& CONTAINS ( __grades, FirstAttemptPass[Test Type], __p, FirstAttemptPass[Grade], "S" ), "YES",
NOT CONTAINS ( __grades, FirstAttemptPass[Test Type], __o )
&& CONTAINS ( __grades, FirstAttemptPass[Test Type], __p, FirstAttemptPass[Grade], "S" ), "YES"
)
RETURN
SWITCH(
TRUE(),
FirstAttemptPass[Grade]= "I", BLANK(),
FirstAttemptPass[CancelReason] <> BLANK(), BLANK(),
FirstAttemptPass[Grade] = "U", "NO",
Result
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Thank you, @Fowmy. I think this solution will work.
I also learned a lot from the formula. I appreciate it.
Hi @RicFischer ,
Do you need a measure or a column?
Here is a measure:
#_FirstAttemptPass =
VAR currentGrade = MAX ( Table1[Grade] )
VAR _t =
CALCULATETABLE (
VALUES ( Table1[Grade] ),
ALLEXCEPT (
Table1,
Table1[StudentName],
Table1[Course],
Table1[Stage],
Table1[Unit]
)
)
VAR result =
IF (
HASONEVALUE ( Table1[Grade] ),
SWITCH (
TRUE (),
currentGrade = "I", "",
currentGrade = "U", "No",
currentGrade = "S" && "U" IN _t, "No",
"Yes"
)
)
RETURN
result
If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.
Check out my latest demo report in the data story gallery.
Stand with Ukraine!
Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/
Thank you!
@RicFischer
I think I solved it, please check.
FirstAttemptPass Solved =
VAR __o = "Oral"
VAR __p = "Practical"
VAR __grades =
CALCULATETABLE (
Table1,
ALLEXCEPT (
Table1,
Table1[StudentName],
Table1[Course],
Table1[Stage],
Table1[Unit]
)
)
VAR Result =
SWITCH (
TRUE (),
CONTAINS ( __grades, Table1[Test Type], __o, Table1[Grade], "U" )
|| CONTAINS ( __grades, Table1[Test Type], __p, Table1[Grade], "U" ), "NO",
CONTAINS ( __grades, Table1[Test Type], __o, Table1[Grade], "S" )
&& CONTAINS ( __grades, Table1[Test Type], __p, Table1[Grade], "S" ), "YES",
NOT CONTAINS ( __grades, Table1[Test Type], __o )
&& CONTAINS ( __grades, Table1[Test Type], __p, Table1[Grade], "S" ), "YES"
)
RETURN
IF ( Table1[Grade] = "I", BLANK (), IF ( Table1[Grade] = "U", "NO", Result ) )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
I forgot to specify that I needed a column. I consider @Fowmy's answer correct and will mark it as a solution. But, because the data is more complicated than I was remembering, I forgot a couple of fields. Since I recieved an acceptable solution, I'll start a new thread and ask my clarified question I'll write a reply to this thread because my new thread was marked as spam.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
143 | |
97 | |
79 | |
68 |