MAQL - Select all records that enclose a list of dates - gooddata

I'm a bit of a noob in MAQL so I would like to know if it is possible to do the following thing :
I got a list of reservations with a Start Date and a End Date
I would like to be able to compute a metric that would give me (for reservations that match some criteria) the number of reservations that include a given night.
In the end, I want my metric to exist for each date x:
MyMetric(x) = Number of reservations with Start > x and End < x
I tried to do the following request:
SELECT COUNT(Voucher) WHERE Date(Start)<THIS AND Date(End)>THIS
but I'm having trouble setting up a report saying "Well now I want THIS to take all the values in the calendar".
(Voucher is just an attribute from my "Reservation" dimension).
Anyone knows how I can proceed ? The user manual is very difficult to read for someone who does not have an extensive experience with MAQL.

I unfortunately don't believe that what you're trying to achieve is possible with the data model you have. The reason behind this is because each date is associated with a specific action, such as the date in which a trip begins and when it ends. In order for this to work exactly how you want, it would be necessary to add a date dimension in the project that has a record for each date between the Begin and End date (e.g. Event date=generic date to capture a range of different events or snapshot date).
Hope this helps!

Related

VB Validation if Date Falls between Range

I am wondering if some one might be able to assist me with my VB code. I believe I am close, because a lot of the time my code works just fine but I noticed that there might be a weakness to it because at times I get unexpected results. I am thinking I am missing something pretty basic here so bear with me!
Basically, I am trying to create a simple hotel reservation system in a Data Table for a VB project that I created just playing around in my spare time.
What I hope to be able to accomplish is for a user to be able to select a room number from a list box then pick an arrival and departure date. After this happens and they click a button I want the program to be able to compare the Room Number along with the beginning date of the reservation and the end date of the reservation with the room number, beginning Dates and end dates in each row already inside of the Data Table. Anyway, here is basically how my If Statement is structured so far:
For Each data As DataRow In dtRoomReserveData.Rows
If data.Item("RoomNum").ToString.Contains(lstSelectRoomNum.Text) AndAlso data.Item("DateArrive") >= dateArrive.Value.Date AndAlso dr2.Item("DateArrive") <= dateLeave.Value.Date Then
'if there is a reservation in room exists during that Date range display error message to user:
MessageBox.Show("Sorry! That room is already reserved during that date range!")
Exit Sub
End If
Next
Any help offered is greatly appreciated!

Excel Forumla/VBA to skip blank columns for calculation

I have a particular data set that consists of information for projects our company works on. Each project can go through five different statuses and we have a column that records each date the project is put into that particular status.
Now for the Excel part. We are trying to calculate the days in each status and find the total project time. The total is easy to do, because I can use network days between the project submitted date and the project go live date. The statuses, however, are giving me issues because sometimes a project will skip a status, leaving the date field empty. So what happens is a project goes from status B to status D, the formula for days in status "B" look for a date in column "C" to use as the second date in a NETWORKDAYS formula. When it is empty, the IF argument tells the formula to use TODAY() as the second date. What I need it to do is the search the columns to the right (within the given range of A:E for that row) and use that date if it exists. If not, then it can default to TODAY() because this would be an "active" project that has not moved on.
=IF(IF(OR([#STALLED]<>"",[#CANCELED]<>""),"",IF([#INTAKEDATE]="","",IF([#SCOPEATE]="",NETWORKDAYS([#INTAKEDATE],TODAY()),(NETWORKDAYS([#STATUSADATE],[#SCOPEATE])))))<0,"",(IF(OR([#STALLED]<>"",[#CANCELED]<>""),"",IF([#INTAKEDATE]="","",IF([#SCOPEATE]="",NETWORKDAYS([#INTAKEDATE],TODAY()),(NETWORKDAYS([#STATUSADATE],[#SCOPEATE])))))))
This is done for each of the statuses so the table looks something like this:
PROJECTID PROJECTNAME INTAKEDATE SCOPEATE BUILDDATE TESTDATE GOLIVEDATE INTAKEDAYS SCOPEDAYS BUILDDAYS TESTDAYS
If there is any Macro or better formula someone could help me figure out, I'd appreciate it. There is also another field that gives the current status or if the project is considered live if that helps at all. I have excel-block right now and cant think of anything that makes sense for this.
So I figured it out using MIN and by adjusting the IF formulas a bit. Whoever it was that posted about MAX earlier, really helped me out getting me down this path. Kudos to you sir/madam.
I had to add the check to see if SCOPEDATE=BUILDDATE because without that it was returning 1 if the dates matched, with was adding one more day when compared to running the networkdays from INTAKEDATE to GOLIVEDATE.
=IF(OR([#STALLED]<>"",[#CANCELED]<>""),"",
IF([#SCOPEDATE]="","",
IF([#SCOPEDATE]=[#BUILDDATE],0,
IF(NETWORKDAYS([#SCOPEDATE],(MIN([#BUILDDATE],[#TESTDATE],[#GOLIVEDATE])))<0,NETWORKDAYS([#SCOPEDATE],TODAY()),NETWORKDAYS([#SCOPEDATE],(MIN([#BUILDDATE],[#TESTDATE],[#GOLIVEDATE])))))))
I hope this is helpful for someone else.

Find All 'Rental' that dont have 'Bookings' within a given DateRange

Proposal
What im trying to do, is allow people to input a date range, and find all 'Rentals' places that have open days between the provided date range from the user.
My Rentals have a has_many association with "bookings" which contain a start and end date.
What would be the best possible way to get every rental article that has a day that is open within that range.
Issue
I can find all the Rentals that have Bookings that dont overlap with the given time, but that doesnt account for each day. So if there was a booking from 7 Sept to 10 Sept, and the User entered the range 5 Sept to 9 Sept, that record would simply not be included, but in theory there is the 5th-7th open.
My Possible Solution
Im still thinking this problem through, so i have not started coding. But what i was going to do, is find all the Rentals that DONT have bookings that overlap with the provided Date Range, store those in a variable(because these are correct results, because it means not a single day overlaps).
Then i will find all the Rentals that have bookings that DO overlap with the provided Date Range. I will then loop through those bookings, and within that, loop through the Range of Dates provided by the user(DateRange.Each) and check if each single day is within that bookings date ranges, as soon as a single day results in a false value(meaning at least one day doesnt overlap) it will end the loop and add the associated "rental" article to the articles collected early with no overlaps at all.
Concerns
The only issue i have with this solution, is i feel it might not be very optimized or run well, im not sure. At the worst case, i would have hundreds of "rentals' and im not sure how many different "Bookings". I dont think something like this could be done in a single SQL query could it ?
Sample data
Rentals Model
name: string
has_many Bookings
Bookings Model
rental_id: integer
start_date: Date
end_date: Date
The user inputs a DateRange, i want all Rentals that have open days(none taken by a 'Booking' in the range provided.
EDIT
I have been thinking, and i think the best solution is using postgres db, which allows for arrays. Ill then store all the dates of the booking, in the array, instead of storing the range.
Postgres supports checking if all the values in an given array is present in an array in the DB. So i could check if the array of 'wanted days' is 'contained' by a DB array, if it is, it means none of the days are free.

DAX sum different DateTime

I have a problem here, i would like to sum the work time from my employee based on the data (time2 - time 1) daily and here is my query:
Effective Minute Work Time = 24. * 60 * (LASTNONBLANK(time2,0) -FIRSTNONBLANK(time1,0))
It works daily, but if i drill up to weekly / monthly data it show the wrong sum as it shown below :
What i want is summary of minute between daily different times (time2-time1)
Thanks for your help :)
You have several approaches you can take: the hard way or the easier way :). The harder (at least for me :)) is to use DAX to do this. You would:
1) create a date table,
2) Use the DAX calculate function to evaluate your last non-blank and first non-blank values (you might need to use calculate table, but I'm not sure; DAX experts jump in). Then subtract one vs. the other.
This will give you correct values for a given day for a given person. You can enforce the latter condition by putting a 'has one value' guard on the person name so that your measure informs the report author if they're not using it right.
Doing the same for dates is a little trickier. In the example you show you are including the date in the row grouping. But if you change your mind and want instead to have 'total hours worked by person' or 'total hours worked by everyone' you're not done with modelling yet.
Your next step is to use calculate table in combination with calculate to create a measure that returns the total. You'll use calculate table so you evaluate each date and the hours worked on that date by person. Then you'll use calculate to summarize that all down to a single number. If you're not careful with your DAX (or report authoring) you might mix which person you're summarizing for so that your first/last non blank are not at the person level. It gets intense quickly.
Your easier solution, though it might be more limited in its application - depends really on your scenario - is to use the query to transform the data into a summary by day and person using the group by command. This will give you a row per person per day with their start and end times. Then you can quickly calculate the hours worked on that day. Then you can quite easily build visuals on top of the summary data. Of course you give up some of the flexibility of the having a proper data model. However if you have a date table, a person table, and your summary table and then setup your relationships correctly you can achieve answers to the most common questions.

How would a db be designed to accept reservations everyday except holidays?

Hope the titel of my question makes sense.
We are building reservations app.
The key stumbling block right now is how to handle reservation dates.
For instance, accordding to their specs, users can make reservations everyday except during holidays.
So, if a user makes a reservation for say, 11/20/2014, if that date is available, it is presented to user for booking.
If that date is not avaialble, the next 30 available dates are presented to the user to choose from.
I have the code to do this check but my question, how do I include the date information that users can compare to the the date they selected?
Sorry guys because I am using an old browser? it won't allow me to add my comments.
So, I am adding it here.
I am just trying to clarify that what I am confused about is how to handle dates that need to be stored on the database.
For instance, whatever date a user selected as preferred event date will need to be compared to the date on our database to see if that date is available for the event.
Where and how should I store that date on the database?
One option might be a secondary table with blackout dates. Outer join to this table and then check if a date returns that is within the range of dates being requested. No joined data, then clear to book.