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
kenneth0596
Frequent Visitor

Calculate sum between date range

Hi all,

 

Below is my sample data.

FeeStart DateEnd Date
120001/1/20216/30/2021
120001/1/202112/31/2021

 

I have also created a custom date table (CALENDAR(MIN(Sample[StartDate].[Date]),MAX(Sample[EndDate].[Date])). What I'm trying to achieve is a simple bar chart where x axis is the month from date table and y axis is the fee column from sample data. I know this can be done by extracting all the dates between start and end date and then calculate the daily cost (fee/# of days) however this method would generate too much data and not sustainable in long run. 

 

Any help would be greatly appreciated! Thanks!

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi, @kenneth0596 

Please check the below picture and the sample pbix file's link down below.

 

All measures are in the sample pbix file, and all steps are numbered in front of each measure.

 

Picture4.png

 

1 Fee Total =
CALCULATE (
SUMX( 'Sample', COUNTROWS(Dates) * 'Sample'[Fee] /(1+ DATEDIFF('Sample'[Start Date], 'Sample'[End Date],DAY ))),
FILTER (
'Sample',
'Sample'[Start Date] <= MAX ( Dates[Date] )
&& 'Sample'[End Date] >= MIN ( Dates[Date] )
)
)
 
2 Fee Total Fix =
SUMX(VALUES(Dates[Month Name]), [1 Fee Total])
 

 

 

https://www.dropbox.com/s/sk5hf1pr4sku69i/kenneth.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

5 REPLIES 5
kenneth0596
Frequent Visitor

Hi @Jihwan_Kim,

 

I have a follow up question hoping you can help me.

Basicially I now have to merge this table (Table 1) with other ones (Table 2, Table 3) and create a matrix out of the merged data.

I also have to establish a relationship between merged table and date table in order for the data from Table 2 + Table 3 to populate correctly.

 

The relationship however will cause an issue with the measure, it only returns the daily rate instead of total (daily rate * # of days). Is there any way to fix this?

 

Thank you in advance for your time! 

Hi, @kenneth0596 

I am not sure whether I understood your question correctly.

If you want to create an active relationship, I suggest re-create my previous measure.

If you want to create an inactive relationship, I suggest using the USERELATIONSHIP DAX function for other measures.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Jihwan, thanks for replying!

 

I have appended three tables (table 1, table 2, table 3) into one and then use the data from appended table to populate a matrix.

 

What I have noticed is that data from table 1 (the one that uses your measures) only works if I disable the relationship between appended table and date table. The data from table 2 and table 3, however, needs an active relationship. So I'm now in this dilemma where part of the data requires relationship and other part doesnt. 

 

Once again, thank you for your advice!

 

Jihwan_Kim
Super User
Super User

Hi, @kenneth0596 

Please check the below picture and the sample pbix file's link down below.

 

All measures are in the sample pbix file, and all steps are numbered in front of each measure.

 

Picture4.png

 

1 Fee Total =
CALCULATE (
SUMX( 'Sample', COUNTROWS(Dates) * 'Sample'[Fee] /(1+ DATEDIFF('Sample'[Start Date], 'Sample'[End Date],DAY ))),
FILTER (
'Sample',
'Sample'[Start Date] <= MAX ( Dates[Date] )
&& 'Sample'[End Date] >= MIN ( Dates[Date] )
)
)
 
2 Fee Total Fix =
SUMX(VALUES(Dates[Month Name]), [1 Fee Total])
 

 

 

https://www.dropbox.com/s/sk5hf1pr4sku69i/kenneth.pbix?dl=0 

 

Hi, My name is Jihwan Kim.

 

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

 

Linkedin: linkedin.com/in/jihwankim1975/

Twitter: twitter.com/Jihwan_JHKIM

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Thank you, Jihwan! 

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.