Forum Discussion

qngu's avatar
qngu
Frequent Visitor
4 years ago
Solved

Squaring & Adding Values from Different Rows Within the Same Column

The problem can best be described with an example below:

Table1:
Date        | group | Value

1/1/2000 | A        | 10

1/1/2000 | B        | 5

1/2/2000 | A        | 11

1/2/2000 | B        | 7

 

I would like to calculate the sum of the squared difference for each date between groups A and B. For the example above, it would be (10-5)^2 + (11-7)^2.

 

Any help greatly appreciated. Thanks. 

  • qngu 

     

    Put below Measure in Card and you will get your answer...

     

    Your Need=
    SUMX
    (
       SUMMARIZE(
          'Table',
          'Table'[Date],
          "need",
          POWER(
          (CALCULATE(MAX('Table'[Value]),'Table'[Group] = "A") - CALCULATE(MAX('Table'[Value]),'Table'[Group] = "B")), 2)),
     MAX([need]))

2 Replies

  • ddpl's avatar
    ddpl
    Solution Sage

    qngu 

     

    Put below Measure in Card and you will get your answer...

     

    Your Need=
    SUMX
    (
       SUMMARIZE(
          'Table',
          'Table'[Date],
          "need",
          POWER(
          (CALCULATE(MAX('Table'[Value]),'Table'[Group] = "A") - CALCULATE(MAX('Table'[Value]),'Table'[Group] = "B")), 2)),
     MAX([need]))
  • qngu's avatar
    qngu
    Frequent Visitor

    Thanks. I didn't think about using the SUMMARIZE function like that.