Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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?

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

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.

View solution in original post

4 REPLIES 4
v-stephen-msft
Community Support
Community Support

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
Not applicable

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

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
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?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.