PowerBI unable to detect time type in get data - time

I get data from a folder where my file name has format Watches_20220315_095127 its in date and time format. But Power BI is unable to detect when the time starts with "0" i.e 095127 it displays error. Can you please help me. I need that time from file name to be used in powerbi report. Power BI works fine when my time has the following format.
Watches_20220315_105127
Watches_20220307_184253
Watches_20220301_144421
PowerBI not detecting as time for below format
Watches_20220315_095127

Assuming that you have the file name as a column in Power Query (PQ), you need to convert that text into a format that PQ can turn into a Date. You can do something like this by getting the sections of the string using Text.Range (Where [Column1] is the name of your column).
DateTime.FromText(
Text.Range([Column1], 8, 4) & "-"
& Text.Range([Column1], 12, 2) & "-"
& Text.Range([Column1], 14, 2) & " "
& Text.Range([Column1], 17,2) & ":"
& Text.Range([Column1], 19,2) & ":"
& Text.Range([Column1], 21,2)
)
This will split out the text into a YYYY-MM-DD HH:MM:SS format that can use DateTime.FromText to convert it into a date time.
You will have to set the field to be a date time type for PQ and then DAX to pick it up as a date time. In the below example the 4th row that has a time of 09:30:01 will now be converted to a correct date time.

Related

If Else Formula for Date field in Crysal Reports that keeps Date format - not string

I have a formula in Crystal Reports to convert for a particular date. The formula is working, but converts the field to a string, and I need the field to be a date as I am exporting as a CSV file and then loading data to a table.
Is there a way to use this same logic but have the field remain as a date
and not a string? Below is the current logic that I am using:
if totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'dd/MM/yyyy') = "01/01/1800" then
"01/31/2099"
else
totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'MM/dd/yyyy')
Maybe like this
if totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'dd/MM/yyyy') = "01/01/1800" then
"DATE '2099-31-12'"
else
"DATE '" & totext((Date(Year({Command.RENEWAL_DT}), Month({Command.RENEWAL_DT}), Day({Command.RENEWAL_DT}))),'yyyy-MM-dd') & "'"
Or use the TO_DATE() function.

ADS retrieve whenchanged with AM or PM

I have a vbs file that queries the domain as below
queryTxt = "<"& domainname &">;" & _
"(&(objectclass=user)(objectcategory=person));"
queryTxt = queryTxt & "SAMAccountName,whenchanged"
But in some servers "whenchanged" is returning values as "8/18/2014 1:20:30 AM" and in some as "12-08-2014 04:54:58". I want to have the returning value as the first date format.
How to update the query so that I get a unique date format.
Queries to the whenChanged attribute return a Date value, so the display format is governed by the regional settings of the computer displaying the query results. Either change the date format in the computer's regional settings, or use a StringBuilder object for building a custom date format.

How do I convert Oracle internal date to Excel date in Excel?

I have a .csv file which was captured from an Oracle database. The date in the .csv file is in the Oracle internal format (not sure what it's called as I'm not familiar with Oracle). It looks like 16474
When I look at that date in the app we use to access the DB, the date is 2/6/2013.
However, when I import the .csv file into Excel and format the column as Short Date, it shows the date as 2/6/1945
I did a random sampling, and it looks like the month/day is always correct, but the year is off by 68 years. I'm assuming this is because Oracle's "beginning of time" is different than Excel's "beginning of time"
Any way to fix this so the dates show properly when importing the Oracle data into Excel?
I don't have access to anything on the Oracle side .. just the .csv file, and Excel. I'm also ultimately importing the Excel file into Access if that helps.
So far, I formatted the Oracle date as Short Date in Excel, and inserted a column next to my date column (J) and used the following:
=DATE(YEAR(J1)+68,MONTH(J1),DAY(J1))
I'm not sure if that is 100% accurate considering leap years
EDIT: I think this code may do it:
Public Sub ReplaceData()
Dim RangeCell As Range
For Each RangeCell In Selection
If IsNumeric(RangeCell.Value) Then
lngDate = CLng(RangeCell.Value)
RangeCell.Value = DateAdd("d", lngDate - 1, "1/1/1968")
End If
Next RangeCell
End Sub
It seems that Oracle may begin on 1/1/1968. I'm not a DB guy but I think that number sounds familiar in other reading I have done.
Here is an example routine that would convert the Oracle date to Excel date, if the above assumption of 1/1/1968 is true.
Sub OracleToExcelCSVDates()
Dim rng as Range 'range of cells containing dates'
Dim cl as Range
Dim strDate As String 'date received from Oracle'
Dim lngDate As Long
Dim newDate As Date 'Converted date'
Set rng = Range("J1:J1000") '< modify this for the number of rows you use in col J'
For each cl in rng 'Iterate over the rng you defined above.'
'Capture the date from Oracle'
strDate = cl.Value
If Not Trim(strDate) = vbNullString Then 'ignore blanks'
'convert to Long data type'
lngDate = CLng(strDate)
'Add the # of days (lngDate) to Oracles base date of 1/1/1968'
newDate = DateAdd("d", lngDate - 1, "1/1/1968")
'Overwrite the cell value with the new converted date:'
cl.Value = newDate
End If
End Sub
More info about Excel dates:
Excel stores serial dates as "a number representing the number of days since 1900-Jan-0, plus a fractional portion of a 24 hour day: ddddd.tttttt . This is called a serial date, or serial date-time."
http://www.cpearson.com/excel/datetime.

How to get selected day/month and year from vb datepicker

in a datepicker i use DateValue(Now) to get the current date . it gives date-month-year
but i require to store only the month value from the same datepicker. wht shoud i do ?
The month can be extracted from the date using the Format$ function:
Print "Month is ";Format$(yourDateValue,"mm")
See this page for all the possibilities.
To get the month as a string use Format as Richard suggests
MsgBox "Month name is " & Format$(yourDateValue, "mmm")
To get the month number use DatePart
MsgBox "Month number is " & DatePart("m", yourDateValue)

How to select Monthly and yearly Dates?

Using VB 6
Using two DTPicker in my project, I want to select monthly and yearly like MM/yyyy and yyyy
Now am Using Daily Date’s like 23/02/2009 (dd/MM/yyyy), I want to use like Monthly (MM/yyyy) and Yearly (yyyy)
My Code
Public Function DaysInMonth(dte As Date) As Integer
Dim d As Date
d = DateAdd("m", 1, dte)
d = DateAdd("d", -1, d)
DaysInMonth = Day(d)
End Function
Private Sub Form_Load()
Dim dteFrom As Date
Dim dteTo As Date
dteFrom = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & "01"), "yyyy-mm-dd")
dteTo = Format(CDate(Year(Date) & "-" & Month(Date) & "-" & DaysInMonth(dteFrom)), "yyyy-mm-dd")
dtpFrom.Value = dteFrom
dtpTo.Value = dteTo
End Sub
Above code is working for daily dates. I want to use monthly and yearly dates also
Now I am selecting a date it showing complete value of the date like 03-02-2009, I want to show monthly and Yearly data’s
Expected Output.
Monthly Date
03/2009 to 04/2009 – It should take a value of 01/03/2009 to 30/04/2009
05/2009 to 05/2009 – It should take a value of 01/05/2009 to 31/05/2009
Yearly Date
2008 to 2008 – It should take a value of 01/01/2008 to 31/12/2008
2008 to 2009 – It should take a value of 01/01/2008 to 31/12/2009
How to select monthly and yearly?
Need VB 6 code Help
You can set the Format on the DTPicker to 3 (dtpCustom) and the CustomFormat to MM/yyyy . This will display month/year format in the text section, but you will still get the full calendar on drop down.
If you want to disable the calendar, you can set UpDown to True. Then you will get up/down buttons instead of the dropdown.
You need to make sure that the hidden value (day part) is correct.
EDIT:
OK, from your comment I understand that you are happy with the date picker, but you want to display the result in a special format?
Example:
Date selected is 20/8/2009 and stored in a date variable a.
Display as 2009:
MsgBox Format(a, "yyyy")
Display as 08/2009:
MsgBox Format(a, "mm/yyyy")
Display as August, 2009:
MsgBox Format(a, "mmmm, yyyy")
Display as Aug, 2009:
MsgBox Format(a, "mmm, yyyy")
Is this what you want?

Resources