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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Add a year variable to a datesbetween

Hi Power Bi Community ! 

 

I'd need your help to perform the following calculation : 

I'd like to be able to have the amount of sales between two dates, and in the formula, the days and months would remain the same, but the year would change according to the one selected.

I've tried something rather handmade, but result expected doesn't appear : 

 

CamilleD_1-1607524013557.png

My data looks like this :

 

CamilleD_2-1607524096030.png

 

Thanks in advance for your help !

 

Best 

 

Camille

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

you can have a try, the selectedyear returns True or False, not a year value. you can try below DAX.

Measure = 
VAR selectedyear=if(HASONEVALUE('Table'[year].[Year]),max('Table'[year]),blank())
return CALCULATE(sum('Table'[amount]),DATESBETWEEN('Table'[year],date(year(selectedyear),1,1),date(year(selectedyear),9,30)))

 





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

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

If the Financial year start on Jan 1, then this simple measure should work

=calculate('Table'[Value],datesytd(calendar[date],"31/12"))

Create a slicer of Month from the Calendar table and select any month.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

HASONEVALUE() returns TRUE when the context for columnName has been filtered down to one distinct value only. Otherwise is FALSE.

You can use Max(), Selectedvalue(), Min() etc. function to get the year value which is selected in the slicer:

Measure = 
VAR _year =
    IF (
        HASONEVALUE ( 'Table'[Year].[Year] ),
        SELECTEDVALUE ( 'Table'[Year].[Year] ),
        BLANK ()
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        DATESBETWEEN ( 'Table'[Year], DATE ( _year, 1, 1 ), DATE ( _year, 3, 31 ) )
    )

re.png

Attached a sample file in the below, hopes to help you.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ryan_mayu
Super User
Super User

@Anonymous 

you can have a try, the selectedyear returns True or False, not a year value. you can try below DAX.

Measure = 
VAR selectedyear=if(HASONEVALUE('Table'[year].[Year]),max('Table'[year]),blank())
return CALCULATE(sum('Table'[amount]),DATESBETWEEN('Table'[year],date(year(selectedyear),1,1),date(year(selectedyear),9,30)))

 





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

Proud to be a Super User!




Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.