Reporting and filtering dates in access 2007? - date

I'm having a customer look up a report between FROM and TO dates. Basically for any month a client can request a report, what I need to do is show the QTY of units in the inventory as of the last day of previous month. So if client is looking to make a report for 12/23/2015 - 12/28/2016 then I need to show the QTY of units in inventory (beginning inventory) on 11/30/2015. I had someone recommend I use DateSerial, but it doesn't seem to do what I want it to do. Basically the FROM AND TO dates are values that I pass on from a Visual Basic application into an empty form and they get used in the report.
I'm not sure if I need to make changes to my queries. Here's what the report does..
With the report, I need to be able to show the client the following...
ItemID
Beginning Inventory (as of last day of previous month)
Unit Price
Bought Units (for report date)
Sold Units (for report date)
Returned Units (for report date)
Subtotal (of bought +sold+returned)
Inventory on hand (beg + subtotal)
So what I do is in my first query I get the Unit Price, and Beginning Inventory (currently not filtering by last day of previous month).
Then I have 3 more queries, one for Bought, Sold and Returned where I link the ItemID's and I filter the TransactionDate (between dates form!formdates!txtFrom and form!formdates!txtTo).
Then I have the last query where I combine the first one with the other 3. Now I'm pretty sure I should include the DATESERIAL() function in the first query? And filter the TransactionDate (this is the column i need to look through to count beginning inv, as well as look for Bought, Sold, Returned Items).
Please help!

The DateSerial() function should return the last day of the previous month. Here is an example query for your problem:
SELECT ID, myDate
FROM Table1
WHERE (((myDate)=DateSerial(Year([enter start date:]),Month([enter start date:]),0))) OR (((myDate) Between [enter start date:] And [enter end date:]));
Documentation: https://msdn.microsoft.com/en-us/library/bbx05d0c(v=vs.90).aspx

Related

How to calculate YTD hours on a Crystal Report?

My company has a payroll program that prints payroll checks and pay stubs using Crystal Reports. The report selects payroll data from a table that has these columns: Hours, PeriodAmount, and YTDAmount. The hours are based on payroll period ending date. The report selects records based on a single pay period end date. So, hours would be selected for a single pay period only. However, we would like to print YTD hours on the pay stub. In other words, hours accumulated from beginning of year to current pay period. Since YTD hours is not a column in the table, would we need to include a sub report to accumulate hours? I don't think running totals would work since we are selecting a single period only. Any thoughts? Thanks.
Yes, a subreport is one option.
Another option is to select all pay periods in the current year and compute the total for the current period using a conditional total. For example, create af ormula that returns the hours if the record belongs to the current period and zero otherwise. Then, SUM that formula per employee. That SUM would give you the hours in the current period.

Dates don't compare properly - Power Bi

I would like to SUMX my Employees Wages, but without Employees who have any sickness record, in which selected date is. So, if Employee was sick from March 3rd to March 5th and Selected Date is March 4th, we don't take that Employee into an account.
That's How I Get A CurrentDay From Slicer:
That's How I Was Trying To At Least Sum Rows, In Which CurrentDay Is Before EndDate of Sickness Record:
And all I get is... The number of TOTAL rows in my sickness records table:
How can I filter that table, to get a valid result?
The structure of your tables is not clear. So, looking through your code you can try following:
COUNTROWS(
FILTER(
table -- ALL(table) as variant, depends on your report ect.
,table[StartDate] <= SELECTEDVALUE(Calendar[Date]) & table[EndDate] >= SELECTEDVALUE(Calendar[Date])
)

Creating yearly comparison after summarizing datediff in Crystal Reports

I created a report that calculated how many days it took a person to complete a task (datediff) and then calculated the avg. number of days it took a group of people to complete the same task (by summing the datediff and then inserting an "avg." function). The time frame used was set by using a "Start date" and "End date" parameter field.
Now, the end user is asking, "how does that average compare to last year?"
I gave a quick answer by creating a Cross tab where I made the "Start date" 01/01/2018 and the end date 12/09/2019 and then grouped by Year in the columns. That is not an exact year-to-year comparison since this is all of 2018 compared to YTD 2019.
I know there is a better way to do this. Any help is appreciated!
Each task has a unique ID, a start date, and an end date
Try using a subreport that shows the same summary data as the primary report, but for a modified set of Start and End Dates. Link the subreport using both Start Date and End Date, but subtract one year from each value. This will allow your primary report to show data for 1-1-2019 through 12-09-2019 and the subreport will show 1-1-2018 through 12-09-2018.
Here is the formula to subtract 1 year from a date.
DateAdd("yyyy", -1, {#StartDate})
You can use this formula in your selection criteria for the subreport or you can create a formula field in the subreport as well, then use that formula field in the selection criteria.

OBIEE YTD Issues

I have a fact table housing different granularity (date grain)
Monthly
Daily
The month data can be accessed by filtering by end of month date or using YYYYMM date format. In OBIEE RPD repo, the fact is set to LAST Aggregation.
I want to perform Year to Date analysis. And I want to sum only month end dates.
Using function TODATE(Measure), it tends to sum up all the data through out the month e.grain
Date Amount YTD TODate(Amount)
31/01/2106 100 100
28/02/2016 200 300
14/03/2016 50 350*
31/03/2016 100 450
I want YTD to ignore 50 and return 400, so also any other dates that falls within any month. And if if I Select 14/03/2016 I want 350 to return.
Thanks.
Alter the table to add a flag, something that flags Y if the record is at the specified monthly grain, and N if the record is not at the specified monthly grain.
In the logical layer, create two distinct LTSs with the first filtering on the flag for Y. This will be where you will calculate and source all your to date measures. The second LTS can either be filtered to N, or can be left to all the data depending on what you want to do with it.
The performance increases should come from the fact that any month measures you build off that monthly LTS will only hit records flagged as month, and will bypass all that other data that is not relevant. So if a user runs a report only asking for monthly measures, the query will automatically filter to that specific data.
What will happen is if a user selects your to date measure and a specific date measure on the same report, OBIEE should fire off two separate queries to get the data and stitch together based on common dimensions.
Could someone create this in the front end? Probably. You would have to do some sort of PERIODROLLING function, and tell it to aggregate at the month level, but I am afraid it may still roll those days up into a larger than desired number. A TODATE function will not work here.

Counting Unique records by Month in Tableau over a year

I have a list of product codes and their sale dates. I want to only count the first ever sale of that product, then SUM the first sales by month of sale.
So if Product A was sold in Feb, Mar and Nov, it only gets counted in Feb.
Here is a badly copied table
Product Code Sales Date WHAT I WANT
-------------------------------------------
A1234 01/02/2014 COUNT THIS
B3333 03/02/2014 COUNT THIS
C5555 06/03/2014 COUNT THIS
A1234 09/03/2014 DON’T COUNT
F567 15/04/2014 COUNT THIS
P000 25/05/2014 COUNT THIS
B3333 01/01/2015 DON’T COUNT
A1234 06/01/2015 DON’T COUNT
P000 19/01/2015 DON’T COUNT
B3333 26/01/2015 DON’T COUNT
K5678 20/02/2015 COUNT THIS
I want my end result to be a graph with months down the side and then a count of first times a product is sold.
Does this make sense? I tried using MIN, but it makes everything AGG, which stops you comparing a date with a date.
UPDATE: commenter pointed out there were two questions in the initial question. Both would be answered with an LOD.
To answer the question: "I want my end result to be a graph with months down the side and then a count of first times a product is sold."
Use a Fixed formula:
count(if
DATETRUNC('month',[Sales Date])={fixed [Product Code]:min(datetrunc('month',[Sales Date]))}
then
[Product Code]
END)
This formula compares the month of the date at each row level to the minimum date for all sales of that same product code. Then it counts up the records where this condition is true.
To answer the question: I want to only count the first ever sale of that product, then SUM the first sales by month of sale.
Since the OP didn't provide sales #'s in the original table I didn't answer the sum part of the question. However, this would also be an LOD and it would look like:
sum(if
DATETRUNC('month',[Sales Date])={fixed [Product Code]:min(datetrunc('month',[Sales Date]))}
then
[Sales]
END)
This is very similar to the above except it sums up sales instead of counting products.
And here is a picture (I added sales and one extra row of sales for product A1234 so you can see that it gets summed as part of the product's first months sales.)
To deep dive into the LOD (Level of Detail) part of this, {fixed [Product Code]:min(datetrunc('month',[Sales Date]))}, Tableau allows you to do calculations based on a specified scope. In this case, the formula gets read like "return the minimum date's month of the sales date for each product code". You can read much more about LOD's on Tableau's site or many Google search results.