one cell for each date between start and end date - sql-server

I searched the web for an answer to this question but wasnt able to find one.
I am trying to create a Dashboard using SS2012 Report builder 3.0.
My Table looks kind of like this:
Machine Task Start_Date End_Date
M01 T01 01.11.2014 02.11.2014
M01 T02 02.11.2014 05.11.2014
M02 T02 01.11.2014 01.11.2014
The Dashboard is essentially a matrix, where the row headers are 'Machine' and 'Task' while the column headers are the Dates.
The cells in the matrix consist of Information about the Tasks (not shown in my example Database)
What I am trying to achieve is, that the contents of the cells are shown in every Date-column between the start and end_date of a task.
One way to theoretically solve this problem would be dublicating every row for each day it is active, but that would create a huge table.
It would be great if someone could provide me with an idea how to solve this problem.
I am still working on this problem and my best approach still seems to be creating new rows for a task if Start_Date <> End_Date
I tried working with the INSERT INTO command, but that does not seem to work with datasets but only with tables.
Something like
IFF(Fields!Start_Date.Value <> Fields!End_Date.Value, INSERT INTO dataset
VALUES(Fields!Machine.Value, Fields!Task.Value, (Fields!Start_Date+1),Fields!End_Date.Value), <Do Nothing>)

I found a similar question regarding the problem with duplication rows for each date between start_date and end_date which is already answered.
For those who also had this problem click here

Related

How to use COUNTIFS based on multiple criteria over different sized ranges?

I have an attendance tracker in which I'm trying to account for each employee type per day.
I have a summary page (sheet1) in which I want the count of each type (A,B,C,D,E) based on the day in cell C2 whether or not they have an X on sheet2 for that day.
Using =COUNTIF(FILTER(Sheet2!$A$5:$GG$969,Sheet2!$A$5:$GG$5=$C$2),"X") I am able to get a total of "X" based on the date in cell C2.
However, I'm having trouble getting the formula to work counting each employee type.
=COUNTIFS(Sheet2!A5:AM31,A7,(FILTER(Sheet2!A5:AM31=C2)),"X")
This gives me an error "Array arguments to COUNTIFS are of different size."
I'm not sure how else to configure this. Below is a link to my sample sheet:
Appreciate any help!
https://docs.google.com/spreadsheets/d/1OdJTwbFsNcR1hO1qzMBGUY4iXcWgDwIAJmBAVE9cs0k/edit?usp=sharing
I think this would work, dragged down for the other groups.
=COUNTIFS(Sheet2!A$6:A$31,A7,FILTER(Sheet2!$6:$31,Sheet2!$5:$5=C$2),"X")
However, I would encourage you to look at this sample sheet (a copy of yours) where I've added a new tab called MK.Help, designed to be hidden, but used as a sort of helper tab to make all sorts of things you might like to do easier. Including the count you asked about.
It has one single formula in cell A2 where you can see what it does.
=ARRAYFORMULA(QUERY(SPLIT(FLATTEN(Sheet2!C5:5&"|"&Sheet2!A6:A31&"|"&Sheet2!B6:B31&"|"&Sheet2!C6:31),"|",0,0),"where Col3<>'' order by Col1"))
try:
={"", ""; QUERY(FILTER(Sheet2!A6:A31, FILTER(Sheet2!6:31, Sheet2!5:5=C2)="X"),
"select Col1,count(Col1) where Col1 is not null group by Col1 label count(Col1)''");
"Total", COUNTA(IFNA(FILTER(Sheet2!A6:A31, FILTER(Sheet2!6:31, Sheet2!5:5=C2)="X")))}

Splitting Multiple Ranges from a Single Range in Google Sheets

I am building a scheduling tool for my company. The structure of my Google Sheets document is a summary page with the entire schedule laid out for each employee in each department. Then, each employee gets their own sheet. In each employee sheets I have a section for Sunday, Monday, and Tuesday (the days each employee works). In each section by day I have a column indicating the hours they are on the clock, and then a column for each department. I have placed a checkbox into each cell and can activate the check box to indicate that this employee will be working in that department at that corresponding time. However, there are times when an employee is in a department more than once per day, meaning that the column with the checkboxes has, for example, checks in the cells corresponding to 7am-10am and 2pm-5pm, with unchecked boxes in the cells corresponding to 11am-1pm.
I have query functions that can pull the start and end times in that department if the employee is only in that department once per day. The output, after some concatenation, is something like "7AM-2PM".
=QUERY(A4:C17, "Select MIN(A) where (C=TRUE)")
=QUERY(A4:C17, "Select MAX(A) where (C=TRUE)")
However, I cannot think of a way to discriminate multiple start and end times. Using the above example, I'd like my output to be "7AM-10AM" and "2PM-5PM". These can be in separate cells or the same cell, doesn't make a difference to me. There can also be formulas in several cells if a subsequent formula needs to operate off a previous one.
I hope this makes sense in the way I have described it. I have been struggling for weeks trying to come up with something and am running out of time. Thanks for any and all help!
try:
=ARRAYFORMULA(IFNA(TEXTJOIN(CHAR(10), 1,
TEXT(FILTER($A4:$A17, IF((B4:B17=TRUE)*({FALSE; B4:B16}=FALSE), 1, )=1), "hh:mm\ - ")&
TEXT(FILTER($A4:$A17, IF((B4:B17=TRUE)*({B5:B17; FALSE}=FALSE), 1, )=1), "hh:mm"))))

Previous years registered: Excel COUNTIF and RETURN for X years

UPDATED screenshot after attempting #Dude_Scott's suggestion:
Desired output of data is in the blue table.
Our data includes users who have registered between 1989-2016.
All have registered at least once.
Some register every year and some skip years.
Our question is for each year, find how many years previous users registered.
We want results to be 0yr, 1yr, 2yr, 3yr, etc., for each year.
Arrays are working correctly.
I've organized the data structure in Excel this way:
1) UserID All Years
For year 1989, result is 0, since it was the first year of data collection.
For year 1990, this formula returns the expected count:
=COUNT(IF($B$2:$B$11613=1989,1/COUNTIFS($A$2:$A$11613,$A$2:$A$11613,$B$2:$B$11613,1989)))
Beginning with year 1991 is where I am tripped up: I can't find for multiple years.
This formula is not working:
=COUNT(IF(AND(OR($B$2:$B$11613=1989,1990,1/COUNTIFS($A$2:$A$11613,$A$2:$A$11613,$B$2:$B$11613,1989,1990)))))
Where do I argue "COUNTIF 0 yr, 1 yr, 2 yr", etc. Thanks in advance. --f66
Since your using COUNTIF, I'm assuming you can use SUMPRODUCT also. In the below screen shot I am using this formula
=SUMPRODUCT(($A$2:$A$11=$D3)*($B$2:$B$11<=F$2))&" yr"
Without a sample of the workbook its a little difficult to determine what the output of your data should look like, but give it a go.
Side note, I would suggest updating the User ID and Years into a table format and giving it a named range, so you don't iterate though tens of thousands of lines with the array formula.
I may be reading this all wrong, but this seems to be a straightforward use case for a pivot table!
Select your data range
Set USERID as your row headings
Set YEARS as your column headings
Set count of USERID as your values
I do not use excel anymore, but below is a link to output for doing this with test data on google sheets.

adding new records to a subform in access

Ah! I think I figured out part of the problem. I am trying to add a new Line Item by using the PartNumber to control the data in the Line Item. This won't work because I use PartNumber as the Primary Key in tblPartData; so it won't let me add an new Line Item because of a Key Violation in tblPartData. What I really need to do is change the FKInvoiceNum.
Basically I built my queries wrong and got confused. So I've just spent about 10 hours banging my head against this. When what I should have done was just written down a describe the problem, and then think about that for awhile. You know step back and look at it from a different angle.
Thanks for providing me a venue where I had to describe my problem succinctly for others. But next time I'll write up my question then let it sit for a couple of hours; to save you all some time.
I have an Access Database with a Form and a Subform for an invoicing system based on queries to the following tables:
tblInvoiceData (InvoiceNum, FKCustomerID, InvoiceDate)
tblCustomerData (CustomerID, all data pertaining to the customer -- sorry there are about 20 fields)
tblLineItemData (FKInvoiceNum, FKPartNum)
tblPartData (PartNumber, PartDescription, FKManufacturerID)
qryInvoiceExpandedData (InvoiceNum, FKCustomerID, InvoiceDate, CustomerID, and all the Customer data fields)
qryLineItemExpandedData (FKInvoiceNum, FKPartNum, PartNumber, PartDescription, FKManufacturerID, and all the manufacturer data fields)
The Main form is frmInvoiceDetails and is based on qryInvoiceExpandedData. The Subform is frmLineItemDetail and is based on qryLineItemExpandedData (includes the following fields: FKInvoiceNum, FKPartNum, PartNumber, PartDescription, FKManufacturerID, ManufacturerID, ManufacturerName) as a continues form.
The problem is that in edit or creation mode I can not change any Line Item Data, or add new Line Items. Can anyone show me where my mistake; I need to be able to change the Line Item Data in the form and can't figure it out.
Apologies if this question type was answered else where, I was unable to find it -- I expect I'm not asking the right question of the search field.

SQL Server query to Crystal Reports

I am trying to move reports that currently run in SQL Server to Crystal Reports.
Essentially the statement I want to reproduce is:
SELECT DATEPART(DD,DATE), COUNT(*)
WHERE FOO = 'BAR'
GROUP BY DATEPART(DD,DATE)
Count the occurrence of records that match a criteria, grouped by date.
I have used the Selection Expert to generate a equivalence relation (to evaluate the records) and would like to use the datepart function in a group by statement. I have gotten the GROUP BY selection expert to group by date - but it is the full timestamp (SS:HH:DD:MM) not by specific day i.e. March 1 2010.
I am sure there is a way to achieve what I want but have yet to find a tutorial explaining this scenario.
Any help you could lend would be appreciated
As with any other SDK/Language, there are many ways to do this. Here is the first one that I can think of:
Get the raw data into Crystal. (Sounds like you already did this)
In Crystal, make a new formula, call it "GroupByDate". In the formula editor, enter:
datepart("yyyy-mm-dd",{mytable.mydatefield})
Go into the Group Expert. Group your report by GroupByDate.
Make a new formula, call it "AddMe". In the formula editor, enter:
iif({mytable.foo="bar",1,0)
Drag & drop your AddMe formula into the details section. Right-click on it to Insert->Summary. Set your summary location as the group footer.
Preview your report and you should see the total counts in every group footer. To simplify the appearance of the report, you can also suppress the display of the detail and grouper header sections.
Again, there are many ways to do this. You can also get creative with a Running Total function. The Crystal Formula Editor has very useful help files. Use the Functions pane to select a function, press F1, and you'll get criteria, examples, etc.

Resources