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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
cprine
Frequent Visitor

Using DATESBETWEEN with relative date ranges

Hello, 

 

I am attempting to sum balances of invoices in a relative date range in the past. However, it returns some results outside of the date window. As of today (10/18/20) it should ONLY return dates between 8/20/20 through 9/19/20. Most items are in that range... however, a handful of results on the table are outside of that range... and I'm about to pull my hair out lol.

Any help would be awesome!

 

 

30-59 OVERDUE Balances = CALCULATE ( 
SUM('ACCOUNTS_PAYABLE'[INVOICE_AMOUNT]), 
ACCOUNTS_PAYABLE[Unpaid?] in {"Unpaid"}, 
DATESBETWEEN( ACCOUNTS_PAYABLE[INVOICE_DUE_DATE], TODAY()-59, TODAY()-30) 
)

 

 

 Screen Shot 2020-10-19 at 6.37.08 PM.pngScreen Shot 2020-10-19 at 6.36.57 PM.png

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

You should have a Calendar Table with a relationship to the invoice date column.  To your visual, drag Date from the Calendar Table.  Write this measure

30-59 OVERDUE Balances = CALCULATE(SUM('ACCOUNTS_PAYABLE'[INVOICE_AMOUNT]),ACCOUNTS_PAYABLE[Unpaid?] in {"Unpaid"},DATESBETWEEN(Calendar[DATE], TODAY()-59, TODAY()-30) 
)

Hope this helps.


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

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

You should have a Calendar Table with a relationship to the invoice date column.  To your visual, drag Date from the Calendar Table.  Write this measure

30-59 OVERDUE Balances = CALCULATE(SUM('ACCOUNTS_PAYABLE'[INVOICE_AMOUNT]),ACCOUNTS_PAYABLE[Unpaid?] in {"Unpaid"},DATESBETWEEN(Calendar[DATE], TODAY()-59, TODAY()-30) 
)

Hope this helps.


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

Thank you @Ashish_Mathur ! That fixed the issue. 

You are welcome.


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

@cprine , Seem fine.

 

Try like

30-59 OVERDUE Balances =
var _min = TODAY()-59
var _max - TODAY()-30
return
CALCULATE (
SUM('ACCOUNTS_PAYABLE'[INVOICE_AMOUNT]),
filter(ACCOUNTS_PAYABLE, ACCOUNTS_PAYABLE[Unpaid?] in {"Unpaid"} && ACCOUNTS_PAYABLE[INVOICE_DUE_DATE] >= _min && ACCOUNTS_PAYABLE[INVOICE_DUE_DATE] <=_max)
)

 

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

 

Please provide your feedback comments and advice for new videos
Tutorial Series Dax Vs SQL Direct Query PBI Tips
Appreciate your Kudos.

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

super

so that a 0 comes out in case there is no data I have completed it with

var _min = today()-365
var _max = today()
VAR Abiertos365 =
CALCULATE(...
...
)
RETURN
IF(ISBLANK(Abiertos365),0, Abiertos365)

Hi,

You may try this measure

=coalesce([Abiertos365],0)

Hope this helps.


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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors