Forum Discussion
Comparing two dates using one calendar table and USERELATIONSHIP
Hi MattAllington, thanks a lot for sharing your article. I did try your calculate formula, but it seems that I am not being returned the correct results. What I did was to first create a column known as Number of Days where the value is just 1 for every row. This is to mirror your Calendar[Working Day] column.
When I performed the following calculation:
Number In Room = CALCULATE(SUM(DateTable[Number of Days]),FILTER(DateTable,DateTable[Date] < MAX(Booking[Booking Check Out Date])))
all I had was 933 as the value for every row in my Number In Room column. This 933 actually refers to the number of rows in my DateTable.
It seems to me that instead of going through row by row in the Bookings table to retrieve the check out date, the above formula had taken the max date in my check out date column and apply it across the whole DateTable. Is my understanding correct?
Do you have any suggestions on how this could be fixed? Thanks.
alexchseng I am still here - just busy :-).
You have posted your DAX formula and it seems to be a calcualted column, but there is a big issue. Every DAX formula can give a different result depending on the context. It is not clear which table your calculated column is in, if there are other tables in your model, if there are other tables it is not clear how they are joined. All these things make a difference and it is impossible to help without full knowledge of all of these things.
Can you post a simple working copy of your model with non-senstive test data? Ideally you should also show what you are trying to achieve, maybe using Excel to illustrate.
You can post workbooks with dropbox or similar.
- alexchseng9 years agoRegular Visitor
Hi MattAllington, thanks for your reply. I have managed to resolve the issue by filtering on the Booking table, as opposed to the DateTable. This also allows me to simply count the rows in my Booking table, as opposed to summing the Number of Days column.
New formula is as follows:
Number In Room = CALCULATE(COUNTROWS(Booking),FILTER(Booking,DateTable[Date] >= Booking[Booking Check In Date] && DateTable[Date] < Booking[Booking Check Out Date]))
Thanks a lot for all your assistance.