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

Total sum by unique user

Hello everybody,

I want to calculate total quantity value at a certain warehouse id (that can be selected via power bi GUI).
The value should be shown at first occurence of a unique customerNumber/user-id, which could also be calculated via minimal order date per user.

I could do it easily on database side via SQL queries (see totalQuantityAtWarehouseId as a correct result). Unfortunately, it doesn't consider the filter context (warehouseId, orderDate), which is why I want to create a measure to calculate it.

Unfortunately, my currently best solution is the following

 

 

Measure = CALCULATE(SUMX (Extended_User_Orders, Extended_User_Orders[correctlySortedOrderQuantity]), Extended_User_Orders[status]="SUCCESS")

 

 

and doesn't sum by user, only row by row.

 

warehouseIduserIdstatusorderNumbercustomerNumberorderDatetotalQuantityAtWarehouseIdMeasure correctlySortedOrderQuantityorderBy
625FF6B0BF8EB2718D65A2A10556585d-f076-4294-be9d-969288e3f31fCANCELLED6760001532-1676000153226.09.2022 07:01  11
625FF6B0BF8EB2718D65A2A10556585d-f076-4294-be9d-969288e3f31fCANCELLED6760001532-1676000153226.09.2022 07:01  -1100
625FF6B0BF8EB2718D65A2A10556585d-f076-4294-be9d-969288e3f31fSUCCESS6760001532-2676000153226.09.2022 07:022111
625FF6B0BF8EB2718D65A2A10556585d-f076-4294-be9d-969288e3f31fSUCCESS6760001532-3676000153226.09.2022 10:57 111
625FF6B0BF8EB2718D65A2A1105958be-7122-4a8e-8682-eded4b6e9b94SUCCESS6760001606-19676000160611.10.2022 07:02 111
625FF6B0BF8EB2718D65A2A1105958be-7122-4a8e-8682-eded4b6e9b94SUCCESS6760001606-2676000160628.09.2022 07:005111
625FF6B0BF8EB2718D65A2A1105958be-7122-4a8e-8682-eded4b6e9b94SUCCESS6760001606-4676000160629.09.2022 07:01 111
625FF6B0BF8EB2718D65A2A1105958be-7122-4a8e-8682-eded4b6e9b94SUCCESS6760001606-6676000160630.09.2022 07:02 111
625FF6B0BF8EB2718D65A2A1105958be-7122-4a8e-8682-eded4b6e9b94SUCCESS6760001606-8676000160601.10.2022 07:01 111

I'm aware that I need to group by user-id and then calculate the sum, but it only works if I create another table (which as a result is unaware of the filter context)

 

 

Table = 
SUMMARIZE (
    ALLSELECTED(Extended_User_Orders),
    Extended_User_Orders[customerNumber],
    "Sales", SUM ( Extended_User_Orders[correctlySortedOrderQuantity] )
)

 

 

Could you please help me with this problem? I'm new to power bi and DAX measures are a bit confusing to me.
Thank you in advance.

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

Hi @chucknorris ,

 

If you want to group summation by userid, you can refer to a formula like this, which applies to group summation, and modify it accordingly according to your actual situation.

Measure = CALCULATE(SUM('Table (2)'[Value]),FILTER(ALL('Table (2)'),'Table (2)'[Attribute]=SELECTEDVALUE('Table (2)'[Attribute])))

vmengzhumsft_0-1666161553895.png

You can see that it is grouped by attribute. In your case, just replace it with "user id ".

 

Best regards,

Community Support Team Selina zhu

 

 

View solution in original post

2 REPLIES 2
v-mengzhu-msft
Community Support
Community Support

Hi @chucknorris ,

 

If you want to group summation by userid, you can refer to a formula like this, which applies to group summation, and modify it accordingly according to your actual situation.

Measure = CALCULATE(SUM('Table (2)'[Value]),FILTER(ALL('Table (2)'),'Table (2)'[Attribute]=SELECTEDVALUE('Table (2)'[Attribute])))

vmengzhumsft_0-1666161553895.png

You can see that it is grouped by attribute. In your case, just replace it with "user id ".

 

Best regards,

Community Support Team Selina zhu

 

 

Hi Selina,

thank you for your answer. 
This solution with measure 

Measure2 = CALCULATE(SUM(testdata_powerbi[correctlySortedOrderQuantity]),FILTER(ALL(testdata_powerbi),testdata_powerbi[userId]=SELECTEDVALUE(testdata_powerbi[userId])))

works! 🙂
Kind regards, 
Chuck Norris

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