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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
subirch
Frequent Visitor

Calculate Weight of Each Product by Employee ID

Hi,

 

I have a table with employee ID, product name along with total, target of products they are selling as depicted in table. How can I calculate weight for each product line for each employee. Obviously the the weight of "Total" would be always 100%. I need the solution using M not in DAX. 

 

EMP IdProduct LinesTargetsWeight
788788A          1,200,000 
788788B        20,000,000 
788788Total        21,200,000 
788789A          9,581,720 
788789B          6,453,456 
788789C        17,400,000 
788789Total        33,435,176 
3 REPLIES 3
subirch
Frequent Visitor

Hi,

 

I have a table with employee ID, product name along with total, target of products they are selling as depicted in table. How can I calculate weight for each product line for each employee. Obviously the the weight of "Total" would be always 100%. I need the solution using M not in DAX. 

 

EMP IdProduct LinesTargetsWeight
788788A          1,200,000 
788788B        20,000,000 
788788Total        21,200,000 
788789A          9,581,720 
788789B          6,453,456 
788789C        17,400,000 
788789Total        33,435,176 
ronrsnfld
Super User
Super User

  • Group by ID
  • In the Aggregation, calculate the weights by which I believe you mean the Percentage of each target as compared with the Total
  • Change the "Source = " line to reflect yourd actual data source
    • The Data Source should NOT include the blank Weight column

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EMP Id", Int64.Type}, {"Product Lines", type text}, {"Targets", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"EMP Id"}, {
        {"Wt", (t)=>Table.AddColumn(t,"Weight", each [Targets] / List.Last(t[Targets])), 
                    type table[Product Lines=text, Targets=Int64.Type, Weight=Percentage.Type]}       
            }),
    #"Expanded Wt" = Table.ExpandTableColumn(#"Grouped Rows", "Wt", {"Product Lines", "Targets", "Weight"})
in
    #"Expanded Wt"

 

ronrsnfld_0-1681731354055.png

 

 

ChielFaber
Super User
Super User

You can create a new column using the m function List.Sum. That will provide you with a grandtotal value in each row. You can then create a new column where you calculate the weight.

 

Take a look at the following youtube video to get an idea how to use List.Sum:

 

https://www.youtube.com/watch?v=Mud1RSqW5pw

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors
Top Kudoed Authors