cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
New Member

Annual cumulative measures between dates

Hello everyone

I have a problem when making a cumulative sum, I explain, I have a table with a quantity and two fields date, from and to, I want to make the cumulative sum of the amount (which is always fixed) considering that the date up may be less, I have set as end date 31/12/2050 those that have not yet ended.

the table is more or less like this

id cant start date end date

1 5 01/01/2018 30/06/2019

2 10 05/05/2018 31/12/2050

3 100 01/05/2019 31/12/2050

4 25 10/06/2019 01/01/2020

5 50 10/05/2020 31/12/2050

And I'm looking for an annual cumulative result of the total so

2018 15 (id 1+2)

2019 135 (id 1+2+3+4 - 1)

2020 160 (id 1+2+3+4+5 - 1 -4)

Thanks a lot

1 ACCEPTED SOLUTION
Super User III
Super User III

@JmSahuco Do you have a DimDate table? Is it unrelated to the table with Cant, ID, in it?

 

You can try something like: 

 

Total Measure =

VAR _MinDate = MIN(DimDate[Date])

VAR _MaxDate = MAX(DimDate[Date])

RETURN

SUMX(FILTER(Table), Table[StartDate] <= _MaxDate && Table[EndDate] >= _MinDate), Table[Cant])

 

Then put DimDate values in the visualization along with the measure above.

 


______________


Check out my Data Stories Gallery Christmas Report: Are you on Santa's Naughty or Nice List?

______________


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

View solution in original post

3 REPLIES 3
Super User III
Super User III

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Super User III
Super User III

@JmSahuco Do you have a DimDate table? Is it unrelated to the table with Cant, ID, in it?

 

You can try something like: 

 

Total Measure =

VAR _MinDate = MIN(DimDate[Date])

VAR _MaxDate = MAX(DimDate[Date])

RETURN

SUMX(FILTER(Table), Table[StartDate] <= _MaxDate && Table[EndDate] >= _MinDate), Table[Cant])

 

Then put DimDate values in the visualization along with the measure above.

 


______________


Check out my Data Stories Gallery Christmas Report: Are you on Santa's Naughty or Nice List?

______________


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

View solution in original post

Me ha servido mucho la solución, sólo he tenido que realizar un ligero cambio

 

funcion = var fmin=min('2-Calendario'[Date])
var fmax=max('2-Calendario'[Date])
return calculate(
sum( table[cant]), FILTER( ALL(table),table[Fecha_Inicio]<=fmax&&table[Fecha_Fin]>=fmin))
 

 

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors