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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.