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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
dx249
Frequent Visitor

How to calculate sum over by partitioning rows in PowerBI ?

Hello Everyone,

I greatly appriciate your help here, I am trying to get the sum of rows partition by row value in powerBI as we do in SQL

 

SUM(ORDER_QUANTITY) over (Partition by Product_code)

 

for the below table.

QA.png


I could not find it to do in powerBI, how to do in PowerBI? Help me here

I tried 

 

Desired_output = calculate(sum(table[ORDER_QUANTITY]),filter(allselected(table),table[PRODUCT_CODE]=MAX(table[PRODUCT_CODE])))

 

Also tried

 

Desired_output = calculate(sum(table[ORDER_QUANTITY]),allexcept(table, table[PRODUCT_CODE]))

 

But getting wrong values.

Thanks in Advance,
DataDX.


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

Hi @dx249 ,

 

If you want the output changed by the slicer, you need to use a measrue.

The calculated column will not change according to the slicer.

Based on your description, I have created a simple sample:

vjianbolimsft_0-1685433499515.png

Please try:

 

Output = 
CALCULATE(SUM('Table'[ORDER_QUANTITY]),REMOVEFILTERS('Table'[NEW_C],'Table'[ORDER_QUANTITY]))

 

Final output:

vjianbolimsft_1-1685433557766.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-jianboli-msft
Community Support
Community Support

Hi @dx249 ,

 

If you want the output changed by the slicer, you need to use a measrue.

The calculated column will not change according to the slicer.

Based on your description, I have created a simple sample:

vjianbolimsft_0-1685433499515.png

Please try:

 

Output = 
CALCULATE(SUM('Table'[ORDER_QUANTITY]),REMOVEFILTERS('Table'[NEW_C],'Table'[ORDER_QUANTITY]))

 

Final output:

vjianbolimsft_1-1685433557766.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ahmedx
Super User
Super User

Share sample pbix file to help you.

dx249
Frequent Visitor

Hi @Ahmedx ,

I undestood the issue, it was happening because the calculated column getting sum again, so getting the high(wrong) values.

But still i have an issue,could you please help me.  The calculated column is not changing according to the slicer ( for example, i have a YEAR date sclicer, whenever i select the different year the calculated column is not changing and it is always showing for entire period not for the selected year), how can i change this?

Thanks in Advance


dx249
Frequent Visitor

Hi Ahmedx,

Thanks for the resposne, I tried your answer, but still i am getting the wrong values like this below


2023-05-12_08h05_18.png

Also, I tried this one, still getting the wrong values.

Total  = 
    CALCULATE(
        SUM('table'[ORDER_QUANTITY]),
        FILTER(
            'table',
            'table'[Product_code] = EARLIER('table'[Product_code])
            )   
)



Thanks in Advance.

Ahmedx
Super User
Super User

pls try this

Screen Capture #1105.png

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.