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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Calculating a $ value for a calendar year from two date columns

Good Afternoon Forum Members,

 

I'm hoping that some of you are able to assist myself in what seemed like a simple task, but that is currently driving me Insane. The brief is to determine the total $ value per calendar year, when I have monthly cost value per record, with a start date in one column and the finish date in another. I'm looking to create a measure which would be used in a card visual to show $ values for 2020, 2021 and 2022 etc.

 

Simple Data Schema Below

 

Column 1 - Mthly $ Cost

Column 2 - Start date

Column 3 - Finish date

 

Please forgive my ignorance, I am very new to Power BI, and I expect that I'm tieing myself in knots, any help would be appreciated. I have tried to use the following, but do not understand how to parse the correct dates into the filter.

 

TotalCosts $ = CALCULATE(SUM('Table1'[Mthly Costs $]),FILTER(VALUES('Table1'[Start Date]), 'Table1'[Start Date] <= MAX(DateDimension[DateKey])), FILTER(VALUES('Table1'[Finish Date]), 'Table1'[Finish Date] >= MIN(DateDimension[DateKey])))

 

 

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

First unpivot columns start date and finish date,and you will see:

Screenshot 2020-09-14 174844.png

Then create 3 columns as below:

 

year = YEAR('Test table'[Date])
Month to the end = 
 IF(DAY('Test table'[Date])=day(EOMONTH('Test table'[Date],0)),12-MONTH('Test table'[Date]),13-MONTH('Test table'[Date]))

 

Total = 'Test table'[Mthly Cost $]*'Test table'[Month to the end]

 

 

And you will see:

QQ图片20200914195221.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

@Anonymous , try like

 

TotalCosts $ = CALCULATE(SUM('Table1'[Mthly Costs $]),FILTER('Table1', 'Table1'[Start Date] <= MAX(DateDimension[DateKey]) && 'Table1'[Finish Date] >= MIN(DateDimension[DateKey])))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Greg_Deckler
Community Champion
Community Champion

@Anonymous Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

 

Maybe:

 

TotalCosts $ = 
  VAR __Max = MAX(DateDimension[DateKey])
  VAR __Min = MIN(DateDimension[DateKey])
  VAR __Table = 
    FILTER(
      'Table1',
      ([Start Date]>=__Min && [Finish Date]<=__Max)
    )
RETURN
  SUMX('Table1',[Mthly Costs $])

 



Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

ItemMthly Cost $Start DateFinish Date
a500001.01.202031.12.2020
b500001.06.202030.06.2021
c500001.01.202131.12.2021

 

The output would be a value per calendar year (x3 measures, one for each year being considered). Therefore the output for 2020 should as be follows based on the data range calculations:

CY20:

item a = $5000 * 12mths = $60000

item b = $5000 * 6mths of CY20 = $30000

item c = $5000 * 0mths as not in CY20 = $0

 

Total value expected value for CY20 = $90000

 

Hope this makes more sense to the community.

Hi @Anonymous ,

 

First unpivot columns start date and finish date,and you will see:

Screenshot 2020-09-14 174844.png

Then create 3 columns as below:

 

year = YEAR('Test table'[Date])
Month to the end = 
 IF(DAY('Test table'[Date])=day(EOMONTH('Test table'[Date],0)),12-MONTH('Test table'[Date]),13-MONTH('Test table'[Date]))

 

Total = 'Test table'[Mthly Cost $]*'Test table'[Month to the end]

 

 

And you will see:

QQ图片20200914195221.png

For the related .pbix file,pls see attached.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
negi007
Community Champion
Community Champion

@Anonymous I think you want to show the value for 3 sepearate years in your dashboard. You can create 3 measures for each of years as below and use them in your visual

 

2020_Val = CALCULATE(SUM('Line Chart%'[Value]),YEAR=2020)
2021_Val = CALCULATE(SUM('Line Chart%'[Value]),YEAR=2021)
2019_Val = CALCULATE(SUM('Line Chart%'[Value]),YEAR=2019)
 
let me know if it helps you



Did I answer your question? Mark my post as a solution!
Appreciate your Kudos



Proud to be a Super User!


Follow me on linkedin

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

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.