cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Helper I

## Weighted Average

Good Afternoon,

I've been struggling with an issue in my task.

My data looks like:

Date                  Company                  Country              Orders                     Type                Rotation Index Value
1/01/2017            Apple                      EEUU                   5                            Day                            4.5

1/01/2017            Google                    EEUU                   8                            Day                            3.5

1/01/2017            Amazon                  EEUU                   2                            Day                            9.5

1/01/2017            Apple                      EEUU                   3                            Week                         2

1/01/2017            Google                    EEUU                   1                            Week                         6

1/01/2017            Amazon                  EEUU                   9                            Week                         1

2/01/2017            Apple                      EEUU                   9                            Day                            9

2/01/2017            Google                    EEUU                   0                            Day                           5

2/01/2017            Amazon                  EEUU                   2                            Day                            2

3/01/2017            Apple                      EEUU                   5                            Day                            7

3/01/2017            Google                    EEUU                   7                            Day                           8

3/01/2017            Amazon                  EEUU                   1                           Day                            9.5

...

8/01/2017            Apple                      EEUU                   6                            Week                         4.5

8/01/2017            Google                    EEUU                   4                            Week                        3.5

8/01/2017            Amazon                  EEUU                   10                          Week                         9.5

...

31/01/2017          Apple                      EEUU                   3                            Month                        2.5

31/01/2017          Google                    EEUU                   1                           Month                        0.5

31/01/2017          Amazon                  EEUU                   6                          Month                         3.5

So what I want to do is to show in a chart the "Rotation Index Value" weighted by the "Orders". The problem is that I need to show the value for each day, last day of the week and last day of the month.

As you can see the column "Type" tells me if the day is a end of day, end of week or end of month(Day-Week-Month). I will put a Slicer that will choose between these three options when I pass from Month to Week or Day in the graphic (as it is needed the value of the last day of the Month/Week, not a sum or the Average, Maximum, etc.).

The problem is that as you can see I need to give a value for example for day 1, which would be (4.5*5 + 3.5*8 + 9.5*2) / (5+8+2) = 4.63
Now I am only able to give a value that does not weigths my average and just makes the (4.5 + 3.5 + 9.5)/3 = 5.83 --> which is incorrect.

For the end of week is the same procedure, I would neet to weight the different Index Rotation Values with the column Orders just for the day that has the type Week.

How can I perform this weighted average so I can give the value for each day-end of week-end of month?

Maybe I have not explained myself very clear, but many thanks for your time.

4 REPLIES 4
Microsoft

@SSS,

(4.5*5 + 3.5*8 + 9.5*2) / (5+8+2) equals to 4.63 but not 3.86. Create a masure using DAX below and check if you get expected result.

`Weighted average = CALCULATE(SUMX(Table,Table[Orders]*Table[Rotation Index Value]),ALLEXCEPT(Table,Table[Date],Table[Type]))/CALCULATE(SUM(Table[Orders]),ALLEXCEPT(Table,Table[Date],Table[Type]))`

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Helper I

Hi Lydia,

Your solution seems a good one but I have an aggregated problem that I forgot to tell.

The column "Orders" is not in my current table but in a table (let's called it Table2) that is related to the actual table of the problem by the "Date"  column.

Is it possible to do your solution but using the column from the Table2?

thanks!!!!

Microsoft

@SSS,

You can create a Orders column in the current table to bring relevant values of Table2 using DAX, then apply the above DAX formula.

If you have questions about how  to create the Orders column, please post sample data of your Table2.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Regular Visitor

Hi,

=DIVIDE(SUMX(Tablename,Tablename[Orders]*Tablename[RotationIndexValue]),SUM(Tablename[Orders])).

Announcements

#### Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

#### Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

#### The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors