I currently have a QUERY function which is set up based on a start date cell and an end date cell, formula as below:
=QUERY(Haulage!$A$3:$L$29," Select * Where A >= date """&text('2022 Stats'!S1, "yyyy-mm-dd")&""" AND A <= date """&text('2022 Stats'!T1, "yyyy-mm-dd")&"""")
This is working fine but I would like to adapt it so I can also narrow the query down further with the use of a dropdown. I have the following IF formula for this:
=IF('2022 Stats'!V1="All TOCs",""," AND LOWER(K) = LOWER('"&'2022 Stats'!V1&"') " )
This seems to yield the correct results but I am struggling to get the two to work together......
Link to sheet: https://docs.google.com/spreadsheets/d/1wTWuvFwMTqJ-sjIZbXWpGOS1WKwpODj2R8KAzqlqkuw/edit?usp=sharing
Try:
=QUERY(Haulage!A3:L29,
"where A >= date '"&TEXT('2022 Stats'!S1, "yyyy-mm-dd")&"'
and A <= date '"&TEXT('2022 Stats'!T1, "yyyy-mm-dd")&"'"&
IF('2022 Stats'!V1="All TOCs",,"
and lower(K) = '"&LOWER('2022 Stats'!V1)&"'"))
Related
I have similar problem statement of (PowerBI/DAX: Unable to correctly compare two dates)
where I'm selected the start date and end date from slicer and wrote DAX for the measures as
Start_Date = CALCULATE(Min('Calendar'[Date]),ALLSELECTED('Calendar'))
End_Date = CALCULATE(Max('Calendar'[Date]),ALLSELECTED('Calendar'))
And I use them to compare with a column and return TRUE or FALSE.
IsTrue_Flag = IF(table[prod_date]>=[Start_Date] && table[prod_date] <= [End_Date], TRUE, FALSE)
But all my values are turning as TRUE which is not the case.
Where did I go wrong with the DAX? please help
I'm trying to select data between an hour range, without using extract to be able to use the indexes in the table. I do the query like this:
SELECT *
FROM activities
WHERE "dateParam"::timestamp >= '21:00:00'::timestamp
AND "dateParam"::timestamp <= '23:00:00'::timestamp;
But I get an 22007 state and it doesnt work, how could I be able to do it?
Try:
SELECT *
FROM activities
WHERE "dateParam"::timestamp >= current_date + '21:00:00'::time
AND "dateParam"::timestamp <= current_date + '23:00:00'::time;
A timestamp needs a date portion so add it.
I'm trying to select records from a DB2 Iseries system where the date field is greater than the first of this year.
However, the date fields I'm selecting from are actually PACKED fields, not true dates.
I'm trying to convert them to YYYY-MM-DD format and get everything greater than '2018-01-01' but no matter what I try it says it's invalid.
Currently trying this:
SELECT *
FROM table1
WHERE val = 145
AND to_date(char(dateShp), 'YYYY-MM-DD') >= '2018-01-01';
it says expression not valid using format string specified.
Any ideas?
char(dateshp) is going to return a string like '20180319'
So your format string should not include the dashes.. 'YYYYMMDD'
example:
select to_date(char(20180101), 'YYYYMMDD')
from sysibm.sysdummy1;
So your code should be
SELECT *
FROM table1
WHERE val = 145
AND to_date(char(dateShp), 'YYYYMMDD') >= '2018-01-01';
Charles gave you a solution that converts the Packed date to a date field, and if you are comparing to another date field, this is a good solution. But if you are comparing to a constant value or another numeric field, you could just use something like this:
select *
from table1
where val = 145
and dateShp >= 20180101;
I have a list of events and their dates. I can use the below formula to get today's (well sort-of as it is incorrectly filtering the date) information.
=query(A:B, "Select * Where toDate(A) = todate(now())")
Now I would like to show the events for the entire upcoming week but the below formula, which I though might work, doesn't
=query(A:B, "Select * Where toDate(A) = todate(now())+1")
With query:
=query(A:B,"Select * where A >= date '"&text(today(),"yyyy-mm-dd")&"' and A<=date '"&text(today()+7,"yyyy-mm-dd")&"' ")
but one of the = should be excluded, depending on which 7 days are required.
I do a select and its working perfect but I want to change it to a select with a from and to date, how would I change my sample to do this? I will get the date from a richfaces calender,
I have a filter on my page that selects all the values for the sql select. so I want to a start and end date to that filter and only get the results between those dates. only "dd/MM/yyyy" can be used as its not necessary for the time
example of select:
myList = database.createQuery("SELECT t FROM Logging t WHERE t.No = :No and t.customer = :customer and t.project = :project and t.task = :tasks").setParameter("No", getNo()).setParameter("customer", getCustomer()).setParameter("project", getProject()).setParameter("task", getTask()).getResultList();
This resolved it for me: and t.date BETWEEN :startDate AND :endDate at the end and then just added the setParameter with the values I get from richfaces calender and works perfect!