Forum Discussion
Consecutive sum
- 3 years ago
Hi , NKTMS
Thanks for your sample data and end result first!
Here are the steps you can refer to :
(1)My test data is the same as yours.(2)We can add an index column in Power Query to judge the row .
(3)Then we can apply the data to Power BI Desktop, and we can cretae a calculated column.
I create two calculated columns and you can choose which the column you need to get :
Column 1 = var _pre_blank = FILTER('Table','Table'[Index]<EARLIER('Table'[Index]) && 'Table'[Count] = BLANK()) var _blank_index =IF(ISBLANK( MAXX(_pre_blank,[Index])), 0, MAXX(_pre_blank,[Index])) var _value = SUMX( FILTER('Table' , 'Table'[Index]>_blank_index && 'Table'[Index]<=EARLIER('Table'[Index])) , [Count]) return _valueColumn 2 = var _pre_blank = FILTER('Table','Table'[Index]<EARLIER('Table'[Index]) && 'Table'[Count] = BLANK()) var _blank_index =IF(ISBLANK( MAXX(_pre_blank,[Index])), 0, MAXX(_pre_blank,[Index])) var _value = SUMX( FILTER('Table' , 'Table'[Index]>_blank_index && 'Table'[Index]<=EARLIER('Table'[Index])) , [Count]) var _next_blank = FILTER('Table','Table'[Index]>=EARLIER('Table'[Index]) && 'Table'[Count] = BLANK()) var _blank_next=IF( ISBLANK( MINX(_next_blank,[Index]) ) , MAX('Table'[Index])+1 , MINX(_next_blank,[Index])) return IF(_blank_next -1 = [Index] , _value, BLANK())Then we can get the result as follows:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi , NKTMS
Thanks for your sample data and end result first!
Here are the steps you can refer to :
(1)My test data is the same as yours.
(2)We can add an index column in Power Query to judge the row .
(3)Then we can apply the data to Power BI Desktop, and we can cretae a calculated column.
I create two calculated columns and you can choose which the column you need to get :
Column 1 = var _pre_blank = FILTER('Table','Table'[Index]<EARLIER('Table'[Index]) && 'Table'[Count] = BLANK())
var _blank_index =IF(ISBLANK( MAXX(_pre_blank,[Index])), 0, MAXX(_pre_blank,[Index]))
var _value = SUMX( FILTER('Table' , 'Table'[Index]>_blank_index && 'Table'[Index]<=EARLIER('Table'[Index])) , [Count])
return
_value
Column 2 = var _pre_blank = FILTER('Table','Table'[Index]<EARLIER('Table'[Index]) && 'Table'[Count] = BLANK())
var _blank_index =IF(ISBLANK( MAXX(_pre_blank,[Index])), 0, MAXX(_pre_blank,[Index]))
var _value = SUMX( FILTER('Table' , 'Table'[Index]>_blank_index && 'Table'[Index]<=EARLIER('Table'[Index])) , [Count])
var _next_blank = FILTER('Table','Table'[Index]>=EARLIER('Table'[Index]) && 'Table'[Count] = BLANK())
var _blank_next=IF( ISBLANK( MINX(_next_blank,[Index]) ) , MAX('Table'[Index])+1 , MINX(_next_blank,[Index]))
return
IF(_blank_next -1 = [Index] , _value, BLANK())
Then we can get the result as follows:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi Thanks for the solution, although i did come across something. It restarts the sum if the value in count column is 0 but I only want it to restart only if it is blank. I hope you can help me with it.