How can I solve this "Add a column 'New Products' which contains False if the order was placed in 2017 and True otherwise" - dataframe

Dataset
The question is, add a new column which contains false if the order was placed in 2017 and True if the order was place in other years. There are 3 different year 2017, 2018 and 2019 in the dataset.
I'm confused as to how to go about it. The "Deliver date" contains values for the dates and the "Product ID" contains values for the products. I am new using Python - please I will appreciate your help.
I tried to use this code, but I know it's not right:
df['New product'] = ['Product ID' in i for i in Global_sales.Delivery date]

Related

Updating Due Date based on Invoice Date and Vendor

I am using DocuWare Workflow Designer (uses SQL) to fill in the due date based on the invoice date and vendor name. In the code below I am trying to have it add 15 days to the invoice date if the vendor is "Hueber - Jones & Coontz" otherwise have the Due Date equal the Invoice Date. The code errors out currently and makes the Due Date equal todays date. I am not able to bring up where in the code its failing. Everything in brackets is references to predefined variables in DocuWare.
SELECT [DW_INVOICE_DATE] FROM [AP] WHERE IF [DW_VENDOR_NAME] = 'HUEBER - JONES & COONTZ' [DW_DUE_DATE] = DATEADD(DD,15,[DW_INVOICE_DATE] ELSE [DW_DUE_DATE] = [DW_INVOICE_DATE]
Thanks in advance.
I don't know how DocuWare works, it it's just simple SQL this is the command:
UPDATE [AP]
SET [DW_DUE_DATE] = (CASE
WHEN [DW_VENDOR_NAME] = 'HUEBER - JONES & COONTZ' THEN DATEADD(DD,15,[DW_INVOICE_DATE])
ELSE [DW_INVOICE_DATE]
END)

Need some advice writing a sql query

I have a view with columns [Date], [ProductId], [NewProduct]. Where [Date] is always [yyyy-mm-01], so for a given month, [NewProduct] can either be 1 or 0 for any productId.
I am trying to create another view based on this one but I want to implement one change. If a product has been marked as [NewProduct] for a given month then it should be marked as a [NewProduct] for the remaining months of that year.
Example This is my original view: ProductView1
As you can see product: 261220 is marked as new product for 2018-05-01.
What I want is I want to create another view derived from this view which should have product: 261220 marked as new product for the rest of the 2018.
I am trying to write a query like this:
CREATE View [dbo].[ProductView2]
As
SELECT [ProductView1].[Date]
,[ProductView1].[ProductId]
,Case WHEN ([ProductView1Prev].[New Product] = 1 AND Month([ProductView1Prev].[Date]) <> 12)
THEN 1
ELSE [ProductView1].[New Product]
END AS [New Product]
FROM [dbo].[ProductView1]
left join
[ProductView1] as [ProductView1Prev]
ON [ProductView1].CustomerId = [ProductView1Prev].CustomerId
and [ProductView1].[Date] = dateadd(month,+1,[ProductView1Prev].[Date])
But the new view Mark product: 261220 as a new product for the next month rather than all the remaining months for that year.
ProductView2 looks like this based on my query:
I am not sure how to achieve the desired output.
try using a "trigger after update" with checking conditions (month bigger than this month by where clause) and check if this column updated then update other columns as well.

Get Next Value within Row Groups in SSRS

I have a problem I'm trying to solve with getting the NextRow value but only within the specific RowGroup.
Here's what I'm trying to do:
if Fields!Interventions.Value is not blank and nextrow(Fields!DateOccurred.Value) within the group is within 4 hours then Y else N
and another column:
if Fields!Interventions.Value is not blank compare currentrow(Fields!DateOccurred.Value) to nextrow(Fields!DateOccurred.Value) and display the differences in hours
But I'm stuck as to how i could do this expression from within SSRS.
I saw the following question:
Get previous,current and Next Record in ssrs report in a page
but the issue with this one is that it doesn't work with Row Groups in SSRS.
Upon further advise, it appears as this isn't possible to do in SSRS, but would be possible in the query itself.
This is the query I'm working with:
SELECT
ROW_NUMBER() OVER(PARTITION BY R.PatientID, PL.ChartLocationID ORDER BY P.DateOccurred ASC) As Row#,
R.NameFirst,
R.NameLast,
P.DateOccurred,
CASE P.Interventions
WHEN 1 Then 'Regular Analgesia'
When 2 Then 'Heat Pack'
When 4 Then 'Cold Pack'
When 8 Then 'Massage'
When 16 Then 'Exercise'
When 32 Then 'Other'
END as Interventions
FROM
ChartEntry P
LEFT JOIN ChartLocation PL on
P.ChartLocationId = PL.ChartLocationId
Inner Join Resident R on
PL.ResidentID = R.PatientID
where
P.DateDeleted is null and
P.DateOccurred >= '01 Jul 2017' and
P.DateOccurred < '01 Aug 2017'
Is it possible to achieve?
Here is some sample data showing the results for the extra two columns:
Easiest and better way is to use LAG/LEAD in your SQL to figure this out.
You can do this in SSRS:
Set your detail value to Previous(Fields!DateOccurred.Value) and the detail row visibility to = RowNumber("yourgroup") = 1 which will hide the first row.
Use one row on the group total, in order to display the last value by setting its value to =Last(Fields!DateOccurred.Value)
The date difference expression check for the detail will be
=Iif(
NOT(Fields!Interventions.Value Is Nothing) AND
DateDiff("h", Previous(Fields!DateOccurred.Value),Fields!DateOccurred.Value)>=4,
"Y",
"N"
)
and for the last line
=Iif(
NOT(Fields!Interventions.Value Is Nothing) AND
DateDiff("h", Last(Fields!DateOccurred.Value),Now())>=4,
"Y",
"N"
)
In the images below, the red line will be hidden with the visibility condition.
Your report will contain only the expected date column, I include the current row date for demonstration.

Crystal Report - Suppressing formula based on two conditions

I am new to crystal report & i stuck in a condition which is not executing due to improper coding. so please help me to resolve this.
Thanks in advance.
Here in my report I wanted to display the sales person name but there are 2 categories in sales person i.e Product & Vertical.
P-XXX-James Koren
V-YYY-BBB-Aditi N
Here I just wanted to pick the sales person name in both categories & for that I used mid function as : Mid({Salesperson Name},11,155) this is for vertical sales person, and for product sales person i used mid function as Mid({Salesperson Name},7,155) both are working fine.
but I wanted to suppress the vertical sales person name if the sales order belongs to product person & vice versa
I tried If condition but its not working properly please insist me for how to combine the 2 formulas & suppress one formula if 2 formulas are evaluated.
you can use if condition on suppress like
If
({your field} = "P" and //product or you can use the query here to find P
PageNumber > 1)
then false //don't Supress
else true //Supress
you can use the same formula on other field's suppress like
If
({your field} = "V" and //Vertical or you can use the query here to find V
PageNumber > 1)
then false //don't Supress
else true //Supress

Date format problems when passing information from Access to Excel

just for documentation and future readers, the problem was solved and the answer is in the discussion between me and #varocarbas
My Application is reading a few columns from access data base and joining those columns into an existing datatable. one of the columns in the database has dates, the column is configured as date and time column in the database and in the data column of the datatable. the problem is when i am extrcting it into excel ,some of the dates are behaving in the oposite direction (i think the term is "english date"). what that i mean by "behaving", is that excel recognize the monthes as the days and the days as the months, for example a date that should be 11 in september 2015 the excel formula month(11/09/2015) is showing that the month is november and not september.
also, the date values in the access column are from sharepoint list that is also configured as dateandtime.. i have a filling that this behaving maybe belongs to excel(?),
here is the importent parts of my code:
' declaring the dateandtime column
Dim colString As DataColumn = New DataColumn("changed")
colString.DataType = System.Type.GetType("System.DateTime")
UnitedTable.Columns.Add(colString)
Storing it from the database:
If Not (IsDBNull(UnitedTable.Rows(i).Item("spcall"))) Then
spcall = UnitedTable.Rows(i).Item("spacll")
rowNum = Searchbinary(spcall) ' check that spcall exist in Projects table via binary search
If rowNum > -1 Then
UnitedTable.Rows(i).Item("somecolumn") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("PmUserName").ToString
UnitedTable.Rows(i).Item("somecolumn") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("OpertionalStatus").ToString
UnitedTable.Rows(i).Item("somecolumn") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("CrmCallNum").ToString
UnitedTable.Rows(i).Item("somecolumn") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("OperationStart").ToString
UnitedTable.Rows(i).Item("somecolumn") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("Approved").ToString
UnitedTable.Rows(i).Item("somecolumn") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("GeneralStatus").ToString
UnitedTable.Rows(i).Item("changed") = db.ReadDataSet.Tables(0).Rows(rowNum).Item("Changed")
Else
' the spcall not exist add it to arraylist
SpCalls_NotExist.Add(spcall)
'UnitedTable.Rows(i).Delete()
End If
Then I am populating it to excel with nested loop.