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
R3mi
New Member

Sum by customer but without grouping / total sales per customer

Hey !

I need a little help for something I thought it would be simple but I'm getting stuck  😅 .

I have a table where each row represents an order line with a product code, the price and quantity per customer it look like this : 

CustomNumberOrderNumberProductNumberQtyPrice
001001001111100
001001001122200
002002001111100
002002001121200
002002002131300
002002002142400

 

Now I need a new column with the total sale per customer, but I don't want to use the group by customer method because I need to keep each row for another step.
I want something like this :

CustomNumberOrderNumberProductNumberQtyPriceTotal per customer
001001001111100500
001001001122200500
0020020011111001400
0020020011212001400
0020020021313001400
0020020021424001400


So first I have created a new column with the Total per product (Price x Qty) but now i'm struggle and can't find a formula without group per customer...
Maybe I need to create another request ? an then add both ?
Thanks  !

1 ACCEPTED SOLUTION
AlienSx
Super User
Super User

Hi, @R3mi add Price x Qty, group by customer (sum new column and retain all columns), then expand missing columns. Table.Group is your friend. 

let
    Source = your_table,
    ttl_prod = Table.AddColumn(Source, "total_product", each [Qty] * [Price]),
    group = Table.Group(
        ttl_prod, "CustomNumber", 
        {{"all", each _}, 
        {"Total per customer", each List.Sum([total_product])}}
    ),
    expand = Table.ExpandTableColumn(group, "all", {"OrderNumber", "ProductNumber", "Qty", "Price"})
in
    expand

View solution in original post

2 REPLIES 2
AlienSx
Super User
Super User

Hi, @R3mi add Price x Qty, group by customer (sum new column and retain all columns), then expand missing columns. Table.Group is your friend. 

let
    Source = your_table,
    ttl_prod = Table.AddColumn(Source, "total_product", each [Qty] * [Price]),
    group = Table.Group(
        ttl_prod, "CustomNumber", 
        {{"all", each _}, 
        {"Total per customer", each List.Sum([total_product])}}
    ),
    expand = Table.ExpandTableColumn(group, "all", {"OrderNumber", "ProductNumber", "Qty", "Price"})
in
    expand

Thanks !

I just missed the last step "expand" ... so simple 😅

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

Top Solution Authors
Top Kudoed Authors