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
sajal161292
Helper V
Helper V

To perform cumulative addition of a column in power bi

Hi,

 

I have prepared the sql query of a report in sql server.

There exists a one to many relationship.

A name can have multiple item_segments against it,an item_segment can have multiple due_dates and a due date should have 6 different order types against it.The requirement is to do cumulative addition of the quantity in all the weeks for a particular name and item_segment.

 

Inkedpowerbi1_LI.jpg

So I would like to have a column cumulativeweekly that could do the cumulative addition of the current week's total with the succeeding weeks.

For Week 50 = Total of week 49 + Total of week 50 = -7302 + (-2834) etc.

Please help me in achieving this.

19 REPLIES 19
Anonymous
Not applicable

@sajal161292,

I make a test in the following sample table. Just create a measure using DAX below.

Cummulative = CALCULATE(SUM(Table[quantity]),FILTER(ALLEXCEPT(Table,Table[Name],Table[item_segments]),Table[week_number]<=MAX(Table[week_number])))

1.JPG

2.JPG


If the above DAX don't help, please share dummy data of your table for us to analyze.

Regards,
Lydia

Hi,

 

Thanks for the solution!!

It is working for me but it is giving the same value for me against every order type.

 

Inkedpowerbi2_LI.jpg

I would like it to have against the order type that are having quantity values in it.

As an example,the order type is having the value -4500 should have cummulative field with value -4500 and the other order types should have 0 against them.

Anonymous
Not applicable

@sajal161292

Could you please export data of your original table to Excel and share me the Excel file via Private Message?

Regards,
Lydia

Hi,

 

By mistake i published it in the accepted solution.

I am unable to attach my excel file via private message.

I can share it with you through google drive if that is covenient for you

Anonymous
Not applicable

@sajal161292,

Please post shared link of  the file.

Regards,
Lydia

Anonymous
Not applicable

@sajal161292,

Please create the following measure and check if you get expected result.

Cummulative = CALCULATE(SUM(Sheet5[quantity]),FILTER(ALLEXCEPT(Sheet5,Sheet5[Name],Sheet5[item_segments],Sheet5[order_type_text]),Sheet5[week_number]<=MAX(Sheet5[week_number])))

Regards,
Lydia

Hi,

 

Thanks for your solution!!

But it is not performing the calculation correctly.

 

Thanks

Anonymous
Not applicable

@sajal161292

Please post expected result in table format based on the sample data you shared to me.

Regards,
Lydia

Hi,

 

Please find the excel file in the location with the result.

I need to represent it in matrix layout:

https://drive.google.com/open?id=1iYZulMyMkohvrNyzGDM_pGQHN9TgacHX

 

Anonymous
Not applicable

@sajal161292,

Create the following measure in your table.

Cumulative3 = IF(MAX(Sheet5[quantity])<>0,
		   CALCULATE(SUM(Sheet5[quantity]),
	                     FILTER(ALL(Sheet5),
				    Sheet5[due_date]  <= MAX(Sheet5[due_date]))), 
		   0    
)

1.JPG


Regards,
Lydia

Hi,

 

I used this in my visual in Power BI but it is not giving me correct results.

 

Inkedpowerbi3_LI.jpg

Anonymous
Not applicable

@sajal161292,

Please review my screenshot. Do you get expected data when importing the sample file which you shared to me into Power BI Desktop and create the measure? Please ensure that you right click your table and select "New Measure" , then apply the DAX formula.
1.JPG

Regards,
Lydia

Hi,

 

Apologies for the inconvenience!!

I would like to represent in the format as illustrated in the screenshot below.

 

powerbi4.PNG

 

I want to calculate the quantity total for each item-segment with different order types foe each week and then pass this value to the next week's pqr order type and similarly doing this operation for the consecutive weeks.

Please help me in doing this.

 

Hi,

 

Apologies for the inconvenience!!

I would like to see it in this format in Power BI now.

 

powerbi4.PNG

 

I want to represent each item-segment and then order types in this format.

Then i will need to take the cumulative total of each week and then pass this total to the pqr order type of next week and similarly for the consecutive weeks  as shown above.

 

Please help me in performing this operation.

Anonymous
Not applicable

@sajal161292,

It is not possible to create the Matrix visual as you describe in Power BI Desktop. You need to add the measure to Matrix visual to represent total of weeks. For more details, please review the following PBIX file.

https://1drv.ms/u/s!AhsotbnGu1NogxF4bHXGWVWMQoBn

Regards,
Lydia

Hi,

 

Is there any other alternative way to do that through matrix visual..like if I create stored procedures for doing this operation in order to store the values for different weeks then will be it be possible to achieve in Power BI?

 

My manager wants it urgently and wants it in this particular format only.

 

Also is there any other tool that can help me in achieving this objective?

 

 

Hi,

 

I have somehow obtained a field as given in the solution below:

 

Inkedpowerbi5_LI.jpg

 

I have created a calculated measure in my visual as:

 

updated_qty = CALCULATE(ShortageData[Cummulative],FILTER(ALLEXCEPT(ShortageData,ShortageData[Name],ShortageData[item_segments]),ShortageData[week_number] +1<=MAX(ShortageData[week_number])))

 

Now in week 49 i need to have the value of the field for one order type as -1500(it is 2066) currently and 0 for the other order type (which is also 2066) currently.

Basically i would need it to replace with the current week's quantity value and the 3rd one should have the rolling quantity total of previous week(which is 2066).

 

It should perform the same operation in the consecutive weeks.

 

I want to use switch statement  which is not helping me in this case.

Can someone please help me in doing it?

Hi,

 

Any pointers are highly appreciated!!

 

Can someone please help me in performing this task?

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!

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.

Top Solution Authors