Excel Using concatenate to compare dates - excel

I have a table containing several columns of which one is a date/time field. I am trying to get a count of instances per day using the following
=COUNTIFS(Table4[Data],"Apple",Table4[Date],(CONCATENATE(V4,"*")))
Data Date Comp Date Count
Apple 6/12/18 1:00 PM 6/12/18 12:00 AM 0
Apple 6/12/18 7:00 AM
Orange 6/12/18 1:30 PM
Apple 6/11/18 11:23 AM
From my understanding of all the moving parts here I should be checking to see if "Apple" exists in the data column and then if "6/12/18" with any amount or type of characters after it exists. If both are true I will then get a count + 1 leaving me with a value of 2 in the above example.
What I actually get however is a 0 unless I match the time portion of date the data to be exactly the same and then removed the wildcard ,"*" from the equation.
Am I doing something wrong or can the wildcard not be used to accomplish what I am trying?
Thanks!

I think you should set your criteria properly.
If you add an additional column next to your Date that contains calculates the integer value of your date using INT() and format the display as DATE (m/d/yyyy) you should then be able to use the following COUNTIFS formula
=COUNTIFS(Table4[Data], "Apple", Table4[Date], "=6/12/18")
See the explanatory video from their Office' support site: https://support.office.com/en-us/article/countifs-function-dda3dc6e-f74e-4aee-88bc-aa8c2a866842

If your [Date] column is a datetime or smalldatetime, you can work with it using CONVERT function, depending on how you want to group.
For example, if you don't care about the time to do the group, you could use the next query:
SELECT CONVERT(varchar,[Date],103), [Data], COUNT(*)
FROM [test_delete].[dbo].[Table1]
GROUP BY CONVERT(varchar,[Date],103), [Data]
This should result in something like this:
[Date] [Data] [Count]
11/06/2018 Apple 1
12/06/2018 Apple 2
12/06/2018 Orange 1
Hope this helps you

If your dates are stored as dates instead of text, use the following:
=COUNTIFS(Table4[Data],"Apple",Table4[Date],">="&V4,Table4[Date],"<"&V4+1)

Related

Excel - Using start_date and end_date values with {=SUM(IF ...)}

I am trying to count data in a range named 'democracy' based on a date start and date end. I have attempted to get this done, but can't seem to fit the pieces together
Component 1
In the SumIf I have:
{=SUM(IF((democracy_highlighted=1)+(democracy_shown=1),1,0))}
The named range democracy contains 2 columns, "highlighted" and "shown", this works in checking both the columns for the value of 1 to be present in one of them.
Component 2
In the countif I have:
=COUNTIFS(democracy_shown,1,DateList,">="&$B$3, DateList,"<="&$B$4)
=COUNTIFS(democracy_highlighted,1,DateList,">="&$B$3, DateList,"<="&$B$4)
This shows data between the start and end dates.
What I need to do is use the {=SUM(IF ...)} component, and limit the results based on start date and end date values?
You could use SUMPRODUCT - something like:
=SUMPRODUCT(SIGN(((democracy_highlighted=1)+(democracy_shown=1)))*(DateList>=$B$3)*( DateList<=$B$4))

Create Date from MM/DD format and include current year? Power Query

I have a table that has a series of Columns with data I need to split out. Example below
STATUS#10/16 12:00:00 (CODE)
I've been able to split it easy enough and when I originally tried to set the date on an older dataset it identified it as a date e.g. 16th Oct 2021 However I started to get errors on this date column and trying with different datasets (10/12, 10/13, 10/14) it is not finding the date. I tried the following query code but I'm receiving errors
[STATUS DATE] is split to 10/14, 10/15 etc
#date( Date.Year(DateTime.LocalNow), Date.Month(Text.End([STATUS DATE]), 2), Date.Day(Text.Start([STATUS DATE]),2))
However I'm getting a function error so I tried
Date.From(Date.Day(Text.Start([STATUS DATE]),2) & Date.Month(Text.End([STATUS DATE]),2) & Date.Year(DateTime.LocalNow)
I have also tried to do this from an example column however the query created is looking at the cell value e.g. if 10/14 then 14/10/2021 else if 13/10 then 14/10/2021. This method i feel is prone for error once I include a larger dataset.
Is there anyway I can determine the date value based on mm/dd format? But with year end in mind, make the YYYY be determined by current year unless we move into Jan and then I don't want the Oct, Nov, Dec value showing as 2022.
You don't really show what your original data looks like.
But if it is like:
Source
Then you can use this code in the Add Custom Column dialog:
let
split=Text.SplitAny([STATUS DATE],"#/ "),
mnth = Number.From(split{1}),
dy = Number.From(split{2})
in
#date(Date.Year(DateTime.LocalNow()),mnth,dy)
The Text.SplitAny function lets you input a list of delimiters and the text will split on all of them. So it is relatively simple to extract the month and day values
to create:
Split [STATUS DATE] one more time into [Month] and [Day] column, using the "/" as a separator. Then you don't have to bother with 1 or 2 digit numbers and you can simply use this formula:
#date(Date.Year(DateTime.LocalNow()), [Month], [Day])
DateTime.LocalNow() is a function, so you need to add the brackets.
[Month] and [Day] are numbers already, so you don't need the Date.Month() or Date.Day() functions.

converting a twitter date string into a datetime field in excel

I have a number of excel strings in the format "Mon Nov 25 17:20:47 +0000 2019"
I found an earlier post that recommended using =DATE(RIGHT(O2,4),MONTH(DATEVALUE(1 & MID(O2,5,3))),MID(O2,9,2)) to create a usable date field. However, this drops the time which is an important piece of information.
How can I include the time with the date in order for excel to recognize and sort all the information included in the field?
Thank you in advance!
You can just use the same logic with the date formula, but use TIME instead of DATE and of course extract the correct time into the formula =TIME(MID(O2,12,2),MID(O2,15,2),MID(O2,18,2))
Edit:
to combine them both in one field, you will need to add them =DATE(RIGHT(O2,4),MONTH(DATEVALUE(1 & MID(O2,5,3))),MID(O2,9,2)) + TIME(MID(O2,12,2),MID(O2,15,2),MID(O2,18,2))
The rationale of this is because:
Date is expressed in whole numbers i.e. 1 = 01/01/1900, 2 = 02/01/1900, 3 = 03/01/1900... 43794 = 25/11/2019, etc.
Time is expressed as a fraction of the day i.e. 0.5 = 12 hrs/12PM, 0.66666 = 16 hrs/4PM, etc.
so lets say you have 1/1/2019 12.00 PM, the date part that gives 1/1/2019 will be 43466 and the time part will be 0.5. Adding them together will give you 43466.5, and when converted to a date time format it will show as 1/1/2019 12:00 PM.
You can use string functions to create an unambiguous date string, then turn it into a date/time value with a mathematical operation (adding the time value in a string form).
=(MID(A1,9,2)&"-"&MID(A1,5,3)&"-"&RIGHT(A1,4))+MID(A1,12,8)
You'll need to format the result as something appropriate: eg: dd-mmm-yyyy hh:mm

How to convert DB2 string column with different formats of datetime to datetime?

I have a varchar column [DB_TIMESTAMP] in a (DB2) table which get data from different sources/environments, This column have different formats in it like:
11/15/2019 11:30:02
11/15/2019 11:22 AM
2019/11/15 11:15 AM
I have to put remarks using CASE in my query to find if there is any row that has 2 hours delay from current DateTime with this column data then mark them pending.
I tried like following, but it need the column with DateTime format which it is not because of different format of data entered in it:
CASE WHEN days (current date) - days(DB_TIMESTAMP))>2
[for checking 2 hours difference]
I think, this column needs to be converted into DateTime then try with above may work, but how:
Please help.
Shamshad Ali
Try Something May it helps:
CASE WHEN DAYS (Replace (CONVERT(nvarchar (500), CURRENT_DATE ,106),' ','-') as current_date)
- DAYS(Replace (CONVERT(nvarchar (500), DB_TIMESTAMP ,106),' ','-') as DB_TIMESTAMP))>2

How to find the first date of the month for a set of data in vba

I have a set of data as such:
05/06/2015
04/06/2015
03/06/2015
02/06/2015
29/05/2015
28/05/2015
27/05/2015
26/05/2015
25/05/2015
22/05/2015
21/05/2015
20/05/2015
19/05/2015
18/05/2015
15/05/2015
14/05/2015
13/05/2015
12/05/2015
11/05/2015
08/05/2015
07/05/2015
06/05/2015
05/05/2015
04/05/2015
30/04/2015
29/04/2015
28/04/2015
27/04/2015
24/04/2015
23/04/2015
22/04/2015
21/04/2015
20/04/2015
17/04/2015
16/04/2015
15/04/2015
14/04/2015
13/04/2015
10/04/2015
09/04/2015
08/04/2015
07/04/2015
06/04/2015
02/04/2015
01/04/2015
31/03/2015
These refer to the weekdays in a year. Among these dates, I want to find the first date of the month. So for example, the month of June, the first date to be identified should be 02/06/2015 and for May be 04/05/2015.
I have tried something like this:
=IF(Cellreference=((Cellreference)-DAY(Cellreference)+1),TEXT(Cellreference,"mmm"),"")
But this only takes the first date of the month. I want it to be the first date in the month in the list of dates given.
Need some guidance on how to achieve this.
I see you use Formula so I can only suggest below:
=MIN(IF(MONTH(AllDateReference)=MONTH(CellReference),AllDateReference,1E+99))
This is an array formula entered using Ctrl+Shift+Enter.
Actual sample:
=MIN(IF(MONTH(A$1:A$46)=MONTH(A1),A$1:A$46,1E+99))
where A$1:A$46 contains all your dates.
Edit1: Display on first date of the month only.
=IF(A1=MIN(IF(MONTH(A$1:A$46)=MONTH(A1),A$1:A$46,1E+99)),A1,"")
Sample:

Resources