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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
JmSahuco
Frequent Visitor

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
AllisonKennedy
Super User
Super User

@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.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as 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 C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

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/
AllisonKennedy
Super User
Super User

@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.


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as 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 C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.