SSRS Report to check conditions and hide table data - sql

This one worked in the past and its deployed but all of a sudden it is started throwing an error. In the Tablix properties I have to check these 3 conditions:
=IIF(DATEDIFF("d", Parameters!startDate.Value, Parameters!endDate.Value) > 30 AND Parameters!startDate.Value > Today() AndAlso Parameters!endDate.Value > Today() AND Parameters!startDate.Value >= Parameters!endDate.Value, True,False)
If I choose end date as todays date it is throwing a message but it is also displaying data. Please help me. It worked earlier, it used to show only message saying date is future date. Now it is displaying data also. I don't want the data to be displayed. TIA.

Is this expression in the Hidden property of the tablix?
If so then the way it is written means that all the conditions must be true for it to be hidden. If I've read it correctly, if startDate was yesterday but endDate was tomorrow, the result will be False so the tablix would display.
If you are just trying to test if any date is in the future or the dates are more than 30 days apart then you could do something like this.
=IIF(
DATEDIFF("d", Parameters!startDate.Value, Parameters!endDate.Value) > 30
OR Parameters!startDate.Value > Today()
OR Parameters!endDate.Value > Today()
, True
, False
)

Related

Trying to accommodate relative defined date, such as 5 days ago, into my fixed date condition in PostgreSQL

I'm trying to condition my WHERE clause to accommodate relatively defined dates into my date filter. I'm pretty confused what type I need to use, if it's CONVERT or TO_DATE function, or if I need to put a CASE WHEN statement into my code.
This is the code that I have written so far:
WHERE event_create_verified_user_success.created_at_utc_date
BETWEEN DATE '2021-11-29' AND DATE '2021-12-05'
And this is the condition of the activity I need to finish:
If the desired date-period is not set manually using fixed dates like from “2021-11-29”
to “2021-12-05”, how would you change the where-clause to consider all data from relative
defined dates: “consider messages created between 10 days and 5 days ago (inclusive)”
I've only started PostgreSQL yesterday and the last time I've handle SQL was probably 4 years ago so I'm pretty confused at how much SQL has changed since then.
Thank you so much for helping!
The basic syntax hasn't really changed in the last 4 years (or even 15 years).
You can use current_date to obtain "today's date". You can subtract days from that
where ... between current_date - 10 and current_date - 5
If created_at_utc_date is a timestamp (= date and time) rather than a date (=date without time) it's better to use a range query though:
where created_at_utc_date >= current_date - 10
and created_at_utc_date < current_date - 4
Note the < combined with the next day you want to compare with.

Error When Trying to Filter Pivot Table With Between Dates Using vb.net

I'm automating a number of reports using a vb.net winforms application. I have one report where I need to update the filter on a Date Field to between 2 dates (Monday & Sunday or the week in question).
I'm getting the dates by having the user select an End Date from a DateTimePicker dateStatusEnd
When the code gets to adding the filter I get the below error message:
The dates are valid because I mistakenly thought I had added them in the wrong order but this gave an error saying the end date had to be less then the start date so it's definitely reading them as errors.
Any ideas how I can resolve this? Code snippet below:
xlSht = aWorkBook.Worksheets("RBA Expiry Dates")
Dim xlPivot As PivotTable = xlSht.PivotTables("PivotTable1")
Dim xlPivotField As PivotField = xlPivot.PivotFields("RBA Expiry Date")
xlPivotField.ClearAllFilters()
If dateStatusEnd.Value.Day = 31 AndAlso dateStatusEnd.Value.Month = 12 And dateStatusEnd.Value.Date.ToString("dddd") <> "Sunday" Then
Dim aDate As Date = dateStatusEnd.Value.Date
Do Until aDate.ToString("dddd") = "Monday"
aDate = aDate.AddDays(-1)
Loop
xlPivotField.PivotFilters.Add2(Type:=XlPivotFilterType.xlDateBetween, Value1:=aDate.ToShortDateString, Value2:=dateStatusEnd.Value.Date.ToShortDateString)
Else
xlPivotField.PivotFilters.Add2(Type:=XlPivotFilterType.xlDateBetween, Value1:=dateStatusEnd.Value.Date.AddDays(-6).Date.ToShortDateString, Value2:=dateStatusEnd.Value.Date.ToShortDateString)
End If
In case anyone else comes across this in the future, it turns out that somewhere between opening the file & applying the filter the Pivot has stop recognising the date column as a date column.
Now I just need to figure out why that's happening 😢

Trigger if Cell date Value is between now and in 24 hours. (Cdate.value)

I'm using Excel 2010 and writing a VBA script that needs to do something if the value is a Cell is between now and in 24 hours. I've looked through dozens of topic and couldn't find a way to efficiently do this.
Here are a few things you need to know.
The script looks for the value (Due Date) in a formula range:
Set FormulaRange = ThisWorkbook.Worksheets("Tasks").Range("F5:F35")
On Error GoTo EndMacro:
For Each FormulaCell In FormulaRange.Cells
With FormulaCell
Let's say that F5 has the following value:
3/9/2016 9:50:00 AM
I am then trying to ask it to do "MyMsg = SentMsg" if the value in range F5:F35 is equal to now or in 24 hours.
Below are a few ways I tried it, and have been unsuccessful at doing so.
1. Doesn't work as it does not consider hours and minutes. It does trigger if the date is tomorrow though, but I need it to check for 24 hours, not +1 day).:
If DateValue(CDate(.Value)) >= Date And DateValue(CDate(.Value)) <= (Date + 1) Then
2. Then I tried to Round Down Now() to the last minute (and adding 1440 minutes for a full day) as the script autoruns itself every minute to check for trigger dates using:
If DateValue(CDate(.Value)) >= Date And DateValue(CDate(.Value)) <= ((Round(Now * 1440, 0) +1440) / 1440) Then
2. Doesn't work as it triggers even if there are more than 24 hours, but doesn't if there is more than 30 hours? (This confuses me). This might be due to me using >= Date? I need to make sure it does send a reminder between Today's 0:00 AM and now + 24 hours.
3. I also tried to use the following but the result is the same as number 2:
If DateValue(CDate(.Value)) >= Date And DateValue(CDate(.Value)) <= (Now + TimeSerial(24, 0, 0)) Then
Am I overthinking this? Is there a easier, simpler way to do this, and if not. What am I doing wrong?
I believe one of the problem is that I can't use between Now and Now + something. Because the script removes the trigger if it is past Now(), so it really has to be a general date and now + time.
Any help will be greatly appreciated, I'm completely stuck there.
Thanks,
Francis M.
There are two possible ways to add 24 hours to the current DateTime (i.e. Now) in Excel VBA; code snippet below demonstrates the use of these functions and also includes a sample IF check based on the condition that the date value in cell "A3" is between Now and (Now+24hrs):
Sub Add24h()
' one possible solution to add 24 hrs
Range("A1").Value = Now + TimeSerial(24, 0, 0)
' another possible solution to add 24 hrs
Range("A2") = DateAdd("h", 24, Now)
'sample logical statement to check if the value is in between two of dates
If (Range("A3") >= Now And Range("A3") <= (Now + TimeSerial(24, 0, 0))) Then
' place you code here
End If
End Sub
The same functionality could be achieved by using Excel Worksheet functions, like shown below:
=IF(AND(A3>=NOW(),A3<=NOW()+1),TRUE,FALSE)
Hope this may help.

Date comparison is incorrect

This is just part of a vba code I am writing and simple date comparison is not working. I have one sheet with tons of data and the vba code creates a pivot table. The code runs fine and does filter out all the past dates but it does not filter out (Feb 3 and Feb 4) for some reason (today is Feb 29). It filters out all the other Feb dates properly but its just those two dates. Anyone know what is wrong?
With ActiveSheet.PivotTables("pivottable1").PivotFields("issuedate")
For Each pi In .PivotItems
If pi < Date Then
pi.Visible = False
End If
Next pi
End With
Have you checked that the column type is a date and not a string? Maybe try CDate(pi)?
If that doesn't work please post the dates that aren't working - maybe by doing a Debug.print(pi).

VB Date and Datetimepicker

I was wondering what was the proper way to create a If statement for if the datetimepicker date is greater than 2 weeks from the current date.
I was thinking something along the lines of
If (datetimepicker.value > DateTimeInterval.Day(14))
but I am not sure the correct way.
You'll need to subtract the current date from the picker date. To get a TimeSpan:
If DateTimePicker1.Value.Date - DateTime.Now.Date > TimeSpan.FromDays(14) Then
'' It's more than 2 weeks
End If