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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Divide a number by sum of cases

Hello guys,

I hope you can help me with this.

 

 Input: A table with two columns. One column shows the Product ID and the other one shows the associated total revenue.

Product IDTOTAL REVENUE
1100
1100
2300
2300

2

300

 

Desired Output:  The TOTAL REVENUE should be devided the the frequency the assocated product ID appears in Column 1.

E.g. ID 1 appears two times in column 1. So the total revenue (100) should be divided by 2 and added to the third column (Split Revenue)

ID 2 appears three times in column 1. So the total revenue  (300) should be devided by 3 and added to the third column (Split Revenue)

 

PRODUCT IDTOTAL REVENUESPLIT REVENUE
110050
110050
2300100
2300100
2300100

 

Thanks so much!

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Go to Add Column in the data tab and paste in the following DAX code. This will create a new column straight into your table. 

 

Column =
VAR __Occurence =
    COUNTX (
        FILTER (
            'associated total revenue',
            EARLIER ( 'associated total revenue'[Product ID] ) = 'associated total revenue'[Product ID]
        ),
        'associated total revenue'[Product ID]
    )
RETURN
    'associated total revenue'[TOTAL REVENUE] / __Occurence

 

 

Karlos_0-1596921300960.png

 

View solution in original post

Hi! I Grouped the tabel by "PRODUCT ID" and counted the rows.

#"Grouped Rows" = Table.Group(Source, {"PRODUCT ID"}, {{"Count", each Table.RowCount(_), Int64.Type}})

2.Group by product id and total revenue.png

then joined the original source with the grouped source.

 

Please consider marking as answer if this resolved your problem.

View solution in original post

4 REPLIES 4
ilton
Helper I
Helper I

Hi! @Anonymous 

Try

let
    Source = Table.FromRecords({
        [PRODUCT ID=1,TOTAL REVENUE=100],
        [PRODUCT ID=1,TOTAL REVENUE=100],
        [PRODUCT ID=2,TOTAL REVENUE=300],
        [PRODUCT ID=2,TOTAL REVENUE=300],
        [PRODUCT ID=2,TOTAL REVENUE=300]
    }),
    #"Grouped Rows" = Table.Group(Source, {"PRODUCT ID"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Join Tables" = Table.Join(Source, "PRODUCT ID", #"Grouped Rows", "PRODUCT ID", JoinKind.Inner),
    #"Added Custom" = Table.AddColumn(#"Join Tables", "SPLIT REVENUE", each Value.Divide([TOTAL REVENUE], [Count])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"})
in
    #"Removed Columns"
Anonymous
Not applicable

Hey @ilton , 

How did you do this step in Power Q. It looks like you've merged the dataset with itself however minus a step or 2. 

Is there a pre-built function for this in Power Q?

= Table.Join(Source, "PRODUCT ID", #"Grouped Rows", "PRODUCT ID", JoinKind.Inner)

Hi! I Grouped the tabel by "PRODUCT ID" and counted the rows.

#"Grouped Rows" = Table.Group(Source, {"PRODUCT ID"}, {{"Count", each Table.RowCount(_), Int64.Type}})

2.Group by product id and total revenue.png

then joined the original source with the grouped source.

 

Please consider marking as answer if this resolved your problem.

Anonymous
Not applicable

Go to Add Column in the data tab and paste in the following DAX code. This will create a new column straight into your table. 

 

Column =
VAR __Occurence =
    COUNTX (
        FILTER (
            'associated total revenue',
            EARLIER ( 'associated total revenue'[Product ID] ) = 'associated total revenue'[Product ID]
        ),
        'associated total revenue'[Product ID]
    )
RETURN
    'associated total revenue'[TOTAL REVENUE] / __Occurence

 

 

Karlos_0-1596921300960.png

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.