Complicated Time Intelligent DAX

msarfaraz

New Member
Joined
Oct 18, 2012
Messages
46
DAX.JPG

I have a complicated case and need your help, its table which connected in BI, the first column is system date and 2nd column is the arrival of guest and third is the departure of the guest, normally system count as stay period i.e. if guest arrival on 29th of Dec 2019 and departure on 1st of Jan 2020 stay night should be 0 (since arrival is on last month and departure on 1st of the month so stay night did not count in current month), however, if arrival on 28th Jan 2020 and departure on 05th Feb system will count only 4 days (28,29,30 and 31st), is there a way we can do the DAX on that. an example is an above scenario.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I think you would be able to use the EOMONTH() function to do this. It allows you to figure out how many days you have until the end of the month, but it can be used to find days from beginning of the previous month as well.
 
Upvote 0
Sorry, I had not noticed that you responded. Here is my belated answer (in case you have not solved it yet).
The EOMONTH() function allows you to find the start and end of the month your system date is in. Once you have the interval ends, you can calculate how many days of the stay fall in the interval.

Start of the active month: =EOMONTH([@[SYSTEM DATE]],-1)+1
Start of the next month: =EOMONTH(@[SYSTEM DATE],0)+1

You have to check if the stay is overlapping the interval. This is true if the following condition is true:
AND([@Departure]>=EOMONTH([@[SYSTEM DATE]],-1)+1,[@Arrival]<EOMONTH([@[SYSTEM DATE]],0)+1)

Then you can use the MAX and MIN functions with the start and end dates to calculate the time in the period.
Putting it all together you get the following formula in the "stays period" column of your table:

=IF(AND([@Departure]>=EOMONTH([@[SYSTEM DATE]],-1)+1,[@Arrival]<EOMONTH([@[SYSTEM DATE]],0)+1),MIN([@Departure],EOMONTH([@[SYSTEM DATE]],0)+1)-MAX([@Arrival],EOMONTH([@[SYSTEM DATE]],-1)+1),0)

I hope this helps.

Book1
ABCDE
1SYSTEM DATEArrivalDepartureStays PeriodTotal Nights Stays
21-Jan-2029-Dec-191-Jan-2003
32-Jan-2030-Dec-192-Jan-2013
43-Jan-2031-Dec-193-Jan-2023
54-Jan-201-Jan-204-Jan-2033
65-Jan-202-Jan-205-Jan-2033
76-Jan-203-Jan-206-Jan-2033
87-Jan-204-Jan-207-Jan-2033
98-Jan-205-Jan-208-Jan-2033
109-Jan-206-Jan-209-Jan-2033
1110-Jan-207-Jan-2010-Jan-2033
1211-Jan-208-Jan-2011-Jan-2033
1312-Jan-209-Jan-2012-Jan-2033
1413-Jan-2010-Jan-2013-Jan-2033
1514-Jan-2011-Jan-2014-Jan-2033
1615-Jan-2012-Jan-2015-Jan-2033
1716-Jan-2013-Jan-2016-Jan-2033
1817-Jan-2014-Jan-2017-Jan-2033
1918-Jan-2015-Jan-2018-Jan-2033
2019-Jan-2016-Jan-2019-Jan-2033
2120-Jan-2017-Jan-2020-Jan-2033
2221-Jan-2018-Jan-2021-Jan-2033
2322-Jan-2019-Jan-2022-Jan-2033
2423-Jan-2020-Jan-2023-Jan-2033
2524-Jan-2021-Jan-2024-Jan-2033
2625-Jan-2022-Jan-2025-Jan-2033
2726-Jan-2023-Jan-205-Feb-20913
2827-Jan-2024-Jan-2027-Jan-2033
2928-Jan-2025-Jan-2028-Jan-2033
3029-Jan-2026-Jan-2031-Jan-2055
3130-Jan-2027-Jan-205-Feb-2059
3231-Jan-2028-Jan-205-Feb-2048
33Total116
Sheet1
Cell Formulas
RangeFormula
D2:D32D2=IF(AND([@Departure]>=EOMONTH([@[SYSTEM DATE]],-1)+1,[@Arrival]<EOMONTH([@[SYSTEM DATE]],0)+1),MIN([@Departure],EOMONTH([@[SYSTEM DATE]],0)+1)-MAX([@Arrival],EOMONTH([@[SYSTEM DATE]],-1)+1),0)
E2:E32E2=[@Departure]-[@Arrival]
E33E33=SUBTOTAL(109,[Total Nights Stays])
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,657
Members
449,462
Latest member
Chislobog

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top