Forum Discussion
Calculating the difference between different rows with a common subject
Hi All,
I am looking to calculate the difference between the grades , between the result sets for each aspect.
So for 'Jim' I want to calculate the difference between his target and in autumn , and then target and spring and the inbetween (so autumn to spring) if possible for both maths and english.
I would really appreciate any help as I am not sure how to tackle this.
This is how the data looks - would I need to pivot it or?
Like I say any help appreciated.
Hopw this makes sense.
Many thanks,
Luke
| Student | Result Set | Aspect | Grade value |
| Jim | Target | CAG - Maths | 3 |
| Jeff | Target | CAG - Maths | 4 |
| Jim | Autumn | CAG - Maths | 2 |
| Jeff | Autumn | CAG - Maths | 3 |
| Jim | Spring | CAG - Maths | 4 |
| Jeff | Spring | CAG - Maths | 4 |
| Jim | Target | CAG - English | 7 |
| Jeff | Target | CAG - English | 9 |
| Jim | Autumn | CAG - English | 4 |
| Jeff | Autumn | CAG - English | 6 |
| Jim | Spring | CAG - English | 7 |
| Jeff | Spring | CAG - English | 2 |
18 Replies
- BA_PeteSuper User
Hi lukeSDM ,
Could you provide a basic example of what you want your end result to be please?
What type of visualisations are you going to use, will it always only be Spring and Autumn or Winter and Summer too, are the seasons/terms always compared to a single target value or can you have seasonal targets, can you use Power Query, are you using Direct Query?
Pete
- lukeSDMHelper V
Hi BA_Pete I want to have a matix that has a column for the difference for each subject.
For Example:
Student English: Target-Autumn Difference English : Autumn to Spring Difference English : Target - Spring Difference Maths: Target-Autumn Difference Maths: Target - Spring Difference Jim +1 -1 +2 +5 -4 Jeff +2 +4 0 0 0 I woulf then like to use conditional formtting on the values so its green if there is positive progress , amber if it stays the same and red if there is negative progress.
Hope this makes sense and thank you very much for your help!
- BA_PeteSuper User
lukeSDM ,
Thanks for the update.
Set up these measures:
_varianceAutumnSpring = VAR autumn = CALCULATE( MAX(lukeSDMTable[Grade value]), lukeSDMTable[Result Set] = "Autumn" ) VAR spring = CALCULATE( MAX(lukeSDMTable[Grade value]), lukeSDMTable[Result Set] = "Spring" ) RETURN spring - autumn_varianceTargetAutumn = VAR autumn = CALCULATE( MAX(lukeSDMTable[Grade value]), lukeSDMTable[Result Set] = "Autumn" ) VAR target = CALCULATE( MAX(lukeSDMTable[Grade value]), lukeSDMTable[Result Set] = "Target" ) RETURN autumn - target_varianceTargetSpring = VAR spring = CALCULATE( MAX(lukeSDMTable[Grade value]), lukeSDMTable[Result Set] = "Spring" ) VAR target = CALCULATE( MAX(lukeSDMTable[Grade value]), lukeSDMTable[Result Set] = "Target" ) RETURN spring - targetThen you can add them to a matrix visual with your dimensions like this:
To get the following output based on the example data provided:
Pete
- lukeSDMHelper V
Thank you for this I have another question.
Is there a way to get this to work if the aspects had different names?
Student Result Set Aspect Grade value Jim Target Target Maths 3 Jeff Target Target Maths 4 Jim Autumn CAG - Maths 2 Jeff Autumn CAG - Maths 3 Jim Spring CAG - Maths 4 Jeff Spring CAG - Maths 4 Jim Target Target English 7 Jeff Target Target English 9 Jim Autumn CAG - English 4 Jeff Autumn CAG - English 6 Jim Spring CAG - English 7 Jeff Spring CAG - English 2 I would like it to work exactly as you have described before but I want to compare "Target Maths" to "CAG - Maths".
Do you know of a way to do this BA_Pete .
I thank you very much for your help so far.
- lukeSDMHelper V
Hi BA_Pete I do not quite understand your explination, sorry I am not very experienced in this.
Would you be able to give me examples of what you have asked me to do.
I have attached an example of my data to help give you a better understanding.
So I would like to compare [Aspect] "KS4 FFT New Eng" [Result set] Year 11 FFT Reported Grade" [Grade] with [Aspect] "Teacher Assessment Eng New" [Result set] "Year 11 Autumn Term" [Grade].
I hope this makes sense and I look forward to your response.
Thank you for all your help so far.
name Result set Aspect Grade Jim Year 11 FFT Reported Grade KS4 FFT New Eng 2 Jim Year 11 FFT Reported Grade KS4 FFT New Maths 2 Jim Year 11 FFT Reported Grade KS4 FFT New Maths 3 Jim Year 11 FFT Reported Grade KS4 FFT New Eng 4 Jim Year 11 FFT Reported Grade KS4 FFT New Eng 3 Jim Year 11 FFT Reported Grade KS4 FFT New Maths 2 Jim Year 11 Autumn Term Teacher Assessment Maths New 2 Jim Year 11 Autumn Term Teacher Assessment Eng New 3 Jim Year 10 Autumn Term Teacher Assessment Eng New 3 Jim Year 10 Autumn Term Teacher Assessment Maths New 1 Jim Year 10 Spring Term Teacher Assessment Maths New 1 Jim Year 10 Spring Term Teacher Assessment Eng New 4 Jim Year 10 Summer Term Teacher Assessment Maths New 1 Jim Year 10 Summer Term Teacher Assessment Eng New 4 Jim Year 10 Interim Autumn Term Teacher Assessment Maths New 1 Jim Year 10 Interim Autumn Term Teacher Assessment Eng New 3 Jeff Year 11 FFT Reported Grade KS4 FFT New Maths 2 Jeff Year 11 FFT Reported Grade KS4 FFT New Eng 3 Jeff Year 10 FFT Reported Grade KS4 FFT New Eng 3 Jeff Year 10 FFT Reported Grade KS4 FFT New Maths 3 Jeff Year 10 Autumn Term Teacher Assessment Eng New 3 Jeff Year 10 Autumn Term Teacher Assessment Maths New 1 This is currently how i have my data in Power Bi which is not good :
(You can disregard the Attitude Aspect as Your previous solution will work for this)
Thank you again.
- BA_PeteSuper User
Hi lukeSDM ,
This new data example makes it a bit more complicated to implement tidily. A couple of questions:
- Are you able to change the data source at all? Adding separate columns for Grade Year, Term, and Subject would make things simpler.
- If not, are you able to use Power Query (i.e. are you using Import mode for your data)? If you are using import mode and can't add the fields to your source as per the question above, then I can show you how to do this in Power Query.
Pete
- lukeSDMHelper V
Hi BA_Pete ,
I am unable to change the data source unfortunatley, the example data I shared is exported from a school information management system directly to an csv file and I then connect to this csv file within Power Bi.
So yes, I believe that I can do bits in Power Query.
I look forward to your response.
Thank you very much fro your help, it is greatly appreciated.
- BA_PeteSuper User
Hi lukeSDM ,
Apologies for the delay.
The more I look at your new scenario, the more confused I get.
Can you clear up the following please?
- Is the 'Teacher Assessment" aspect a target or an actual value?
- Jim, for example has three KS4 FFT New Eng values in year 11, but none of them show which term (Spring, Summer, Autmun) they apply to. How can i distinguish which Target to compare to which Actual?
Thanks,
Pete
- lukeSDMHelper V
Hi BA_Pete ,
I am trying to implement this into my own PBI document but I am confused on how to do this, I have followed your steps for the powerquery part and its come up with the example data but how do i make this work for my real data?
Do i have to copy and paste a bit of your code onto my datas source advanced editor?
Many thanks,
Luke
- lukeSDMHelper V
I cannot post my full reply and as their is HTML issues can anyway help.
- lukeSDMHelper V
Hi
I have been attempting to get your solution to work and it does, to some extent , however when I look at the results it produces they are wrong however when giving you example data i did not incorporate other factors in and i think this is causing an issues.
Please let me give some data that reflects my data source better and see if it makes sense and you could get this to work(I will only use one student as an example and I will include the steps you have alreadty explained to me. I did adapt some of the formula to work with my data a bit better):
The data continues in a very similar pattern for all years with different names and some other changes.
from the example data in the tabel you would expect the autumn variable difference to be -1 as the calculation would do 2 (actual grade) - 3 (target grade) to give them -1 to show they are below target.
however after following your steps but tweaking them to try and fit my datat better I gte the answer of -3 which I am confused on how it would have gotten this answer.
Any help is really appreciated, I feel like it is so close to being resolved.
Thanking you so much in advance,
Luke,
(I have also attached a picture of the data to help with understanding)
Thanks again.
- lukeSDMHelper V
I am having to send a picture of the better example table as for some reason the error is with html is in the table, so sorry but i cannot help that.
please find the other picture i mentioned aswell