Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi everyone, I have searched for an answer to this, but have got stuck in a muddle with DAX so hoping someone could please put me out of my misery!
I have a dataset where I need to calculate the progress of students from lesson 1 to lesson 2.
Student is scored at Lesson 1 then scored again at Lesson 2.
I need to subtract the lesson 1 score from the lesson 2 score to get the Progress value for each Student ID.
Not all students will have a lesson 2 entry (as their lesson 2 may not have taken place yet) - the Progress should only be calculated at Lesson 2.
I was trying to do this under a calculated column, but not sure if a measure would be better? An example of my data is below, I have created a student_lesson column which is the Student ID and Lesson ID concatenated then made an index column based on this, as assessments could be entered in any order so didn't want to make an index based on this.
The Progress column is what I want it to look like (unless a measure is better?)
Assessment ID | Student ID | Lesson No | Score | Student_lesson | Index | Progress |
1 | 1 | 1 | 20 | 11 | 1 | |
35 | 1 | 2 | 100 | 12 | 2 | 80 |
4 | 2 | 1 | 30 | 21 | 3 | |
23 | 2 | 2 | 90 | 22 | 4 | 60 |
65 | 3 | 1 | 40 | 31 | 5 | |
6 | 4 | 1 | 10 | 41 | 6 | |
8 | 4 | 2 | 100 | 42 | 7 | 90 |
I have entered (the latest version of!) my code but have tried all sorts including using the EARLIER function but just can't get the syntax right.
Progress =
var index = tbl_Assessment[index]
var students = tbl_Assessment[Student_ID]
var prevrow =
CALCULATE(
SUMX(tbl_Assessment,tbl_Assessment[Score](
FILTER(tbl_Assessment,
tbl_Assessment[index]<index && tbl_Assessment[Student_ID] = students))))
return
CALCULATE(SUMx(tbl_Assessment,tbl_Assessment[Score]),FILTER(tbl_Assessment,tbl_Assessment[Lesson_No]=2)-prevrow)
Many thanks for any help!
Solved! Go to Solution.
Hi @bigrods ,
Try this calculated column
Process =
IF (
[Lesson No] = 2,
CALCULATE (
SUM ( tbl_Assessment[Score] ),
FILTER (
ALLEXCEPT ( 'tbl_Assessment', tbl_Assessment[Student ID] ),
[Lesson No] = 2
)
)
- CALCULATE (
SUM ( tbl_Assessment[Score] ),
FILTER (
ALLEXCEPT ( 'tbl_Assessment', tbl_Assessment[Student ID] ),
[Lesson No] = 1
)
)
)
You can check more details from here.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @bigrods ,
Try this calculated column
Process =
IF (
[Lesson No] = 2,
CALCULATE (
SUM ( tbl_Assessment[Score] ),
FILTER (
ALLEXCEPT ( 'tbl_Assessment', tbl_Assessment[Student ID] ),
[Lesson No] = 2
)
)
- CALCULATE (
SUM ( tbl_Assessment[Score] ),
FILTER (
ALLEXCEPT ( 'tbl_Assessment', tbl_Assessment[Student ID] ),
[Lesson No] = 1
)
)
)
You can check more details from here.
Best Regards,
Stephen Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Great, thanks so much - this has done the trick - and thanks to @Mikelytics and @sanalytics for their assistance too.
You can follow the below pattern also
Attached link is the pbix file
https://dropfiles.org/WhgoHdhk
Regards
sanalytics
if it is your solution then please like and accept it as your solution
Hi @sanalytics
Thanks for the reply, I am a couple of versions of PBI behind, need to get my IT to upgrade my version next week so unfortunately cannot view your pbix file.
When I run your code, every value in the Progress column is blank - I have searched the code but cannot see anything glaring, it all looks fine. All columns are Whole Number format, would you have any possible suggestions? thanks a lot!
Hi @bigrods ,
I think it would make sense to solve this using measures
one measure for lesson one, one for lesson 2 and one for the delta. To also calulcate the average and single progres I would use the average function.
e.g.
Lesson 1 Score = CALCUATE(AVERAGE(table[lesson score]),table[lesson score]=1)
Lesson 2 Score = CALCUATE(AVERAGE(table[lesson score]),table[lesson score]=2)
Progress = [lesson 2 score] - [lesson 1 score]
THe create a table (or matrix) with the students as row and the three measures as values.
I hope that helps.
Best regards
Mikelytics
Did I solve your request? Please mark my post as solution.
Appreciate your Kudos.
Hi @Mikelytics
Thanks so much, that works to get them into a matrix (see below).
Is it possible to put the measure into a chart, i.e a bar chart showing the no. of students at each progress point (10,20,30 etc?) I have tried (below) but it's rightly not splitting into seperate points. Apologies, I should have figured that out before. Is this where the calculated column comes in?
Many thanks
Hi @bigrods ,
you are right in this case you need a calculated column.
Please try the following calculated column:
CALCULATE(Max(table[score]),
Filter(ALL(table),
table[student ID] = EARLIER(table[student ID]) && table[lesson ID] = 2))
Best regards
Mikelytics
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
94 | |
77 | |
65 | |
53 |
User | Count |
---|---|
145 | |
105 | |
104 | |
90 | |
63 |