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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
bo_at_laurabo
Regular Visitor

Compare two overlapping sets of date ranges

Hi - thought I could nail this, but it keeps going wrong. Might be more complicated than I thought. Looking for your ideas. 

Trying to figure this out using Power Query and Power Pivot / Dax in Excel;

 

Consider this setup; 1) A list of dates that represents rentals of a sort. 2) A second list of dates that represents a rebate period. 

The condition for rebate is 120 days per rebate period. At the moment rebate periods are for one year, thus 120 days within a year. Starting anywhere in a year (not following calendar year, but initiated by first rental after 01-10-2024. Following this the rebate maximum could be reached inside of a rental period when reaching 120 days. Part of the rental with rebate, part without. Furthermore there could be more than one rental at a given date, but it still only uses one day of rebate.

 

Might be easier with some example data as it looks after preparation in Power

Query;

 

1) List of rentals from 3 customers (id):

IdRentsRental/fiscal YearRent startRent endDisp
1sku202429-04-202406-05-202418000
1po202406-05-202426-06-202490000
1he202426-06-202404-09-2024110000
1skn202404-09-202408-09-20246000
1skf202409-09-202431-12-999860000
2sa202416-09-202231-12-9998400000
2sa202316-09-202231-12-2023150000
3ka202413-05-202431-12-9998320000

Disp is the cost in the rental/fiscal year. 

 

2) Rebate periods:

IdRebate schemeRebate startRebate end
1Rebate 12029-04-202431-12-9999
2Rebate 12001-10-202431-12-9999
2Rebate 12001-10-202330-09-2024
3Rebate 12013-05-202431-12-9999

Only one rebate scheme at the moment and always runs for one year after start date. Thus rebate end is not needed, but maybe other rebate schemes will surface later.

 

I believe I need to join these two tables either in Power Query or in the data model in Power Pivot. 

 

If joined i would like to be able to get something like this for customer 2;

IdRebate schemeRebate startRebate endRentsRental/fiscal YearRent startRent endDispYear 2023Year 2024 
2Rebate 12001-10-202330-09-2024sa202316-09-202231-12-2023150000920(92 days of 120 spend in 2023)
2Rebate 12001-10-202330-09-2024sa202416-09-202231-12-9998400000028(28 - up to cap - spend in 2024)
2Rebate 12001-10-202431-12-9999sa202316-09-202231-12-202315000000(obsolete line - no overlap)
2Rebate 12001-10-202431-12-9999sa202416-09-202231-12-9998400000028(same 28 as in line 2!!!)

 

For customer 1 something like this:

idRebate schemeRebate startRebate endRentsRental/fiscal YearRent startRent endDisp20242025
1Rebate 12029-04-202431-12-9999sku202429-04-202406-05-20241800080
1Rebate 12029-04-202431-12-9999po202406-05-202426-06-202490000520
1Rebate 12029-04-202431-12-9999he202426-06-202404-09-2024110000620
1Rebate 12029-04-202431-12-9999skn202404-09-202408-09-2024600000
1Rebate 12029-04-202431-12-9999skf202409-09-202431-12-99986000000

Customer 1 has spend he/hers 120 days within rental in line 3. No new rebate scheme entered for the period after 28-04-2025.

 

Thank you for reading to the end and I am looking forward to any hints you might be able to give me. Tried a bit with chatgpt, but could not nail it - or my prompting are not clear enough.

2 REPLIES 2
lbendlin
Super User
Super User

Do not use fake dates.  Leave these blank.  Otherwise you risk wasting enormous amounts of storage space on date hierarchies.

 

Your id 2 has two rows with Rents sa . Is that intended? Why is Rent start for both in 2022?

Hi Ibendlin

 

Your id 2 has two rows with Rents sa . Is that intended? Why is Rent start for both in 2022?

- it is really one rent, but the data comes from two different economic years. In 2023 you expect 150.000 and in 2024 400.000. The rent begins 16-09-2022, but it not until 01-10-2023 I need to count to a cap of 120 days/rebate period. 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.