Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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!

 

 

  • Anonymous's avatar
    Anonymous
    5 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

  • 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))

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you so much, But how do you deal with the subject in your measure. Here the example after adding subject

      subjectsessionstudentgrade 1grade 2
      10001110010
      100021500
      100012905
      100022905
      2000111009
      2000211001
      200012704
      200022905
           
      subjectstudentdif grad1dif grad2  
      10001100-5010-0 
      1000290-905  minus 5
      20001100-1009 minus 1 
      2000270-904 minus 1 
    • Anonymous's avatar
      Anonymous
      Not 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

  • Anonymous's avatar
    Anonymous
    Not 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.

  • Anonymous's avatar
    Anonymous
    Not 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.