Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Average Weighted Calculation by Month

Good morning

I have a data table that has the following information. The Density column is calculated Kg/ M3

MyKgM3Density
January950143.4647766.62183448
January1600222.1390087.20269715
January1600153.78854410.4038959
February1600172.14129.29469529
February1600165.536289.66555489
February3200432.8862727.39224181
February80066.21451212.0819436
March1600165.536289.66555489
March974154.5005286.30418558
March85085.438089.94872544
March80062.65459212.7684177
March1750264.8580486.60731291

I need to calculate the weighted density, in excel I do it by creating these separate columns (% Total and Den Pond):

MyKgM3Density% TotalDen Pond
January950143.4647766.621834480.228915661.51584163
January1600222.1390087.202697150.385542172.77694348
January1600153.78854410.40389590.385542174.01114058
February1600172.14129.294695290.222222222.06548784
February1600165.536289.665554890.222222222.14790109
February3200432.8862727.392241810.444444443.28544081
February80066.21451212.08194360.111111111.34243818
March1600165.536289.665554890.267827252.588699
March974154.5005286.304185580.163039841.0278334
March85085.438089.948725440.142283231.41553676
March80062.65459212.76841770.133913631.70986511
March1750264.8580486.607312910.292936061.93552019

The % Total column is the result of dividing the kg of each row by the total kg per month, for example the first value of 0.2289 in the first row is made by dividing 950 / (950+1600+1600) x 0.2289 and so with all January rows. For the first row of February it has a value of 0.2222 is the result of 1600 / (1600+1600+3200+800) x 0.2222 and so on each month.

The Den Pond column is the result of multiplying the Density * % Total column, for example in the first row is 6.62 * 0.22 x 1.51 and so each row.

I wish I could have a table with the following information

MyDense
January8.30392569
February8.84126791
March8.67745446

In which the Densi column is the sum of the Den Pond column for each month.

Can someone help me?

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hello @omarbobadilla ,

    You should test the calculated column instead of the measure.

    The calculated column creates the Den Pond column.

    28.png29.png

    More details can be found here.

    Column calculated versus custom

    Best regards

    Stephen Tao

    If this post helps,then consider Accepting it as the solution to help other members find it faster.

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

     

    [Your Table] =
    ADDCOLUMNS(
        DISTINCT( T[Month] ),
        "Dense",
            CALCULATE(
                var __total = SUM( T[Kg] )
                var __dense =
                SUMX(
                    T,
                    var __density = T[Density]
                    var __kg = T[Kg]
                    var __percentTotal =
                        DIVIDE(
                            __kg,
                            __total
                        )
                    var __denPond =
                        __percentTotal * __density
                )
                return
                    __dense
            )
    )

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      It makes me error:

      omarbobadilla_0-1605813617749.png

      Adjust the fields but I get error... Funny thing is, I don't get the variable __dense

      omarbobadilla_1-1605813701773.png

      What's it all about?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hello @omarbobadilla ,

    You should test the calculated column instead of the measure.

    The calculated column creates the Den Pond column.

    28.png29.png

    More details can be found here.

    Column calculated versus custom

    Best regards

    Stephen Tao

    If this post helps,then consider Accepting it as the solution to help other members find it faster.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you very much for the solution, it was exactly what I needed