Minimum of dates selection in Access - sql

I have a date clause for the selection of my data. There are two date fields on my form 'oberflache' which are start and end. I want to choose the minimum of two fields. i.e it should only choose the record based on the date which comes first.Here is the code am trying with.
PARAMETERS [Forms]![oberflache]![start] DateTime, [Forms]![oberflache]![end] DateTime;
SELECT Lau.AN, Lau.Ve, Lau.Du, Lau.Sta, Lau.A, Lau.B, Lau.SW, Lau.Po
FROM Laufzettel
WHERE
Min(Fix(Lau.A)) Between Forms![oberflache]!start And Forms![oberflache]!end))
Or
Min(Fix(Lau.B)) Between Forms![oberflache]!start And Forms![oberflache]!end;
Where AN,Ve,Du,Sta,A,B,SW,Po are the fields from the table Lau. So the cases are
Lau.A Lau.B
1.11.2016 5.11.2016
2.11.2016 3.11.2016
20.10.2016 4.11.2016
4.11.2016 28.10.2016
Here when I give the start and end Dates as 1.11.2016 and
4.11.2016. I want the records to be selected in such a way that if the date of Lau.A or Lau.B is before 1.11.2016 just like in the 3rd record or 4th record they must be left out and the first two are selected.
With the code I tried
It gives me an error that cannot have aggregate function in WHERE clause. What is an alternative for the above?

Related

Summing the value of the aggregate function Last()

enter image description hereI am trying to design a report in ssrs that returns the last opening stock for each product in the dataset. To achieve this I used
=Last(Fields!CustProdAdj_new_openingstockValue.Value).
This works fine. But where I encountered a problem is in getting the sum of all the opening stock for each product. I tried using
=sum(Last(Fields!CustProdAdj_new_openingstockValue.Value))
but I got the error message
[Error on Preview]
Please is there another way to go about this
I have tried using aggregate(), runningValue(), to no avail
This is the dataset
This is the report layout
On previewing having used max()
This is probably easier to do directly in the dataset query but assuming you cannot change that, then this should work...
This assumes your data is ordered by the CustProdAdj_createdon column and that this is a date, datetime or some other ordered value, change this bit if required.
=SUM(
IIF(Fields!CustProdAdj_createdon.Value = Max(Fields!CustProdAdj_createdon.Value, "MyRowGroupNameHere"),
CustProdAdj_new_openingstockValue,
0)
)
Change the MyRowGroupNameHere to be the name of the rowgroup spelled exactly as it is in the rowgroup panel below the main design panel. Case sensitive and include quotes.
What this does is, for each row within the rowgroup "MyRowGroupNameHere", compare the CustProdAdj_createdon date to the max CustProdAdj_createdon across the rowgroup. . If it is the same then return the CustProdAdj_new_openingstockValue else return 0.
This will return the value required on only 1 record within the group.
For example, if you had 1 row per day then only on the last day of the month would a value be returned other than 0 because only the date of the last record would match the maximum date within the group.
Then it simply sums the results of this up.

count only if field has one entry in Tableau

I am using tableau and am stuck in making the field of the following code unique.
"COUNTD(
IF NOT(ISNULL([firstBillingDate]))
THEN [msisdn]
ELSE NULL
END
)"
Basically its counting unique msisdn's for all the columns which have firstbillingDate present (NOT NULL).
The problem is that one msisdn has more than one firstBillingDate. I want to count unique msidns which has only ONE firstbillingdate
Instead of using [firstBillingDate] in that calculation, create an LOD calc to only retrieve one date per msisdns.
{fixed [msisdns] : min([firstBillingDate]}
You can use max or min. I assumed you'd want min to return the earlier date for any multiple dates per msisdns. Now use this in your original calc.

Filter records for Dropdown control

How can I filter rows for my Dropdown control?
Currently I'm binding Items property to column e.g. Items=Table1.Name
but this populates dropdown with all possible rows. I want to filter all rows in which another column meets condition e.g. Table1.Date=Today()
You can use a Filter expression in the Items property of your dropdown control:
Items: Filter(Table1, Date = Today())
And you can select which field of your table to show in the dropdown by using the Advanced view (in the case below, Name, as you had in your example):
Just a note that I had to do something a little more complex for filtering out results for a SQL source where I also needed a Distinct.
The basic idea is I wanted years out of a table, but only last year and whatever years we had listed. Also worth noting the 500 row limit was a bit of an issue against my original date table, and so this only works with smaller tables.
In my case, I needed to create a view to reduce the data granularity
Distinct(Filter('[dbo].[YearList]', YearNumber >= Year(Now()) -1), YearNumber)

Group Entire Crystal Report by Column in Subreport

I am trying to set up the following report so that it is grouped first by "Transfer-In Unit" (d1_10.xinstitute), which is the title of a column that is included in a sub-report, and second by xpid, which is a patient index number used in all tables (except a catalog) in this report. To simplify this question, assume that xpid is indexed in alphabetical order of the patients' names.
See info/examples below:
This report shows patients that have transferred out of a specific unit since the user-inputted date (Name), a row for each date that the patient transferred out of a particular unit (Unit M Transfer-Out Date), chronologically where they next transferred into (Transfer-In Unit), and when they transferred into that unit (Transfer-In Date).
Currently without attempting this grouping the output looks like this:
Name and Unit M Transfer-Out Date are on the parent report
Transfer-In Unit and Transfer-In Date are in a subreport because they both call d1_10.dstartdate but with different criteria.
The goal is to sort by Transfer-In Unit, which is a column in the subreport.
The output should be:
An underlying issue is that to select the chronological next transfer-in following a transfer-out, I have to select a minimum transfer date grouped by xpid. This causes the requirement of an xpid grouping in the sub-report.
I have tried a grouping by d1_10.xinstitute (the unit index) in both the parent- and sub-reports. In the parent report it creates one all-encompassing group, because every row in this report represents someone transferring out of "Unit M". In the subreport it seems to apply the groupings row by row, so each row has two groups, even when the next row is the same patient transferring into the same unit. However this is my best attempt and it looks like this:
Any help/thoughts/ideas much appreciated. Let me know if I can provide any further info.
Thanks

QlikView Set Analysis: use either column number or other unique info from row

I am trying to use Set Analysis in the table below for the column labelled test. I am trying to get sum([Best Dollar]) for the date range specified by the Start and End columns.
This expression returns results, but it's naturally static for each row of the table:
=sum({$<AsAtDate={">=40959 and <=40960"}>} [Best Dollar])/1000
This is what I want to have but it returns 0:
=Sum({$<AsAtDate={">=(num(floor(BroadcastWeekStart2))) and <=(num(floor(BroadcastWeekStart2)))+6"}>} [Best Dollar])/1000
To obtain unique start date serial numbers for each line for the start column (BroadcastWeekStart2) I use the following expression:
=(num(floor(BroadcastWeekStart2)))
How can I specify that the values or calculations used for the start and end columns are used in Set Analysis for the field above?
There is at least one information missing in your question.
Do you want to select on fixed values or should the sum depend on the current time?
For the static version something like
=sum( {$<BroadcastWeekStart2={"40959"}, BroadcastWeekStart2={"<=40960"}>} [Best Dollar])/1000
should work. (Assuming that BroadcastWeekStart2 contains these kind of values.)
Let me show you an example how I calculate values for the current week:
='Count: ' & count({$<start_week={"$(=WeekStart(Today()))"}>} Games)
where the start_week is set in the load script by:
WeekStart(date#(#4, 'YYYYMMDD')) as start_week,