Forum Discussion
group by and difference
Hello all
I thank you in advance for your help with this. I have something like this and I want to do the difference of each grade column between each session for each subject and each student. I try to make a group by in the transform data but there is only the possiblity to make sum and other not relevent functions. I need the difference. What do you suggest for this.
I need to get from table 1 to table 2 in the example.
Thanks a lot for this!
- Anonymous5 years ago
Hi @enath_nakash,
Here are the steps you can follow:
1. According to your requirements, create the data, named Table.
2. Use calculation table.
New Table:
Table_test = SUMMARIZE('Table','Table'[subject],'Table'[student], "dif grad1",CALCULATE(MAX('Table'[grade 1]),'Table'[session]=1)&"-"&CALCULATE(MIN('Table'[grade 1]),'Table'[session]=2), "dif grad2",CALCULATE(MAX('Table'[grade 2]),'Table'[session]=1)&"-"&CALCULATE(MIN('Table'[grade 2]),'Table'[session]=2))3. Result.
You can downloaded PBIX file from here.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 Replies
- amitchandakSuper User
Anonymous , Create two new measures
grade1 diff = calculate(sum(Table[grade1]), filter(Table, table[Seesion]=1)) -calculate(sum(Table[grade1]), filter(Table, table[Seesion]=2))
grade2 diff = calculate(sum(Table[grade2]), filter(Table, table[Seesion]=1)) -calculate(sum(Table[grade2]), filter(Table, table[Seesion]=2))- AnonymousNot applicable
Thank you so much, But how do you deal with the subject in your measure. Here the example after adding subject
subject session student grade 1 grade 2 1000 1 1 100 10 1000 2 1 50 0 1000 1 2 90 5 1000 2 2 90 5 2000 1 1 100 9 2000 2 1 100 1 2000 1 2 70 4 2000 2 2 90 5 subject student dif grad1 dif grad2 1000 1 100-50 10-0 1000 2 90-90 5 minus 5 2000 1 100-100 9 minus 1 2000 2 70-90 4 minus 1 - AnonymousNot applicable
Thank you so much for that!!
How if I want to add to this new table we just created a column from another table ?
I have a table C with a column grade 3 that I want to add to the new table you just created. How does it make sence after your summarize?
Thanks so much
- AnonymousNot applicable
Hi @enath_nakash,
Here are the steps you can follow:
1. According to your requirements, create the data, named Table.
2. Use calculation table.
New Table:
Table_test = SUMMARIZE('Table','Table'[subject],'Table'[student], "dif grad1",CALCULATE(MAX('Table'[grade 1]),'Table'[session]=1)&"-"&CALCULATE(MIN('Table'[grade 1]),'Table'[session]=2), "dif grad2",CALCULATE(MAX('Table'[grade 2]),'Table'[session]=1)&"-"&CALCULATE(MIN('Table'[grade 2]),'Table'[session]=2))3. Result.
You can downloaded PBIX file from here.
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Hi @enath_nakash,
Here are a few ways to Help copying a column to another table:
1. You may try Merge Queriesin Query Editor.
2. If you have a relationship between table 1 and table 2 you can use related function, if not, try the lookupvalue function .
Information about these two fuctions below:
https://docs.microsoft.com/zh-cn/dax/lookupvalue-function-dax
https://docs.microsoft.com/zh-cn/dax/related-function-dax
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.