Facing issue with Date column format in Power BI - powerquery

I have an excel dateset where date column includes date in dd-mm-yyyy format(Proper date) and in text format that too in mm/dd/yyyy format(just text not proper date). want to convert all dates in dd-mm-yyyy format. How to do all in dd-mm-yyyy format in Power Query editor
The question is: In Power Query Editor Perform all necessary action to convert all the dates in the "Date" column to be in "dd-mm-yyyy" format.
I am new in Power BI. Please help on this.
enter image description here

Importing correctly
If you set the right culture, all the inputs are converted to a type date
let
Source = #table(
type table[Date = text],
{ {"7/27/2012"}, {"9/14/2020"}, {"04-11-2020"} }
),
// using the system's current culture
#"Dates" = Table.TransformColumnTypes(
Source,
{ {"Date", type date} }
),
//specify a specific culture
#"US Dates" = Table.TransformColumnTypes(
Source,
{ {"Date", type date} },
"en-US"
)
in
#"US Dates"
date verses text
I'm not clear if you're referring to different date format strings, or actual data types when you say Proper Date, I think you mean the first.
In the query editor where you import dates, it should be type date
If it visually displays out of order, that's okay. It's using your systems current settings.
Once you're in the data model, that is when you pick your date format strings. Notice that both images use the same data, the green is the data type in Power Query.
Blue is the format string that lets you override the defaults.

Related

How to setup a control with month names

In my db i have a column created_at (date_time format). I would like to create an analytical dashboard when it will be possible to filter data by create_at by giving month name (one or more - multiple choice)
I have added a new calculated field "month" in data set with following formula:
formatDate(truncDate("MM",{created_at}),"MM" )
As a result i get new column with strings like "01", "02" etc.
I've created a new parameter:
name: Month
Data type: string
Values: multiple values: {01, 02, 03 ....}
I've created a new control:
name: Month
Style: Multi select drop down
Values: Link to a data set field -> Data set -> Month column
I've created a new filter for Month columns, based on Month parameter
My problem is: how to achieve the same result (filtering by month, multi select) having month names displayed in the control, not "01", "02" etc. Is it possible?
UPDATE
It is much better to have following formula in Month calculated field:
extract("MM",{create_at})
But it does not solve my problem....
What i did, but i really don't like this solution as it is so ugly.....Any better solution is welcome :)
new calculated field month_number, with formula:
extract("MM",{create_at})
new calculated field month_name with formula:
ifelse({Month_number}=1,"Jan",ifelse({Month_number}=2,"Feb",ifelse({Month_number}=3, "Mar",ifelse({Month_number}=4, "Apr",ifelse({Month_number}=5, "May",ifelse({Month_number}=6, "Jun",ifelse({Month_number}=7, "Jul",ifelse({Month_number}=8, "Aug",ifelse({Month_number}=9, "Sep",ifelse({Month_number}=10, "Oct",ifelse({Month_number}=11, "Nov",ifelse({Month_number}=12, "Dec","Error"))))))))))))

Lotus sorting view on orderdate does not work properly

I have created a view in which I also have a column which holds dates. This column can be sorted on ascending and descending. This is my column properties value:
But the problem is that the view does not sort the dates properly:
And here a screenshot of the orderdate field itself:
And here screenshot of the document with the orderdate that is out of order in the view:
Update
Some documents had the orderdate as text instead of date.. I create these documents through a java agent. The field orderdate I fill in like this:
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
But it is saved as text instead of date. Anyone knows why?
Problem was that orderdate field was set by a backend agent and this field was set with a string.
I know saved the current time as a DateTime object and now it works:
DateTime timenow = session.createDateTime("Today");
timenow.setNow();
docOrder.replaceItemValue("Orderdatum", timenow);
It's not clear to me why it's not working for you, but you can brute force it with something like this in the column formula
dateForSure := #TextToTime(OrderDatum);
#Text(#Year(dateForSure)) + "-" + #Text(#Month(dateForSure)) + "-" + #Text(#Day(dateForSure));
Also: your Java code saves a text value because the format() method of SimpleDateFormat returns a StringBuffer. The ReplaceItemValue method generates a text item when its input is a String or StringBuffer. Assuming your form defines OrderDatum as a Time/Date field, you can call Document.ComputeWithForm in your code to force it to convert the text item to a Time/Date. Another method - probably preferable given the potential side-effects of calling ComputeWithForm would be to create a DateTime object in your Java code and pass it to the ReplaceItemValue method instead.
It's because formatterDatumForField.format(currentDateForField) returns a String instead of a date/time value. Assuming that currentDateForField is a date/time value, you should change
SimpleDateFormat formatterDatumForField=new SimpleDateFormat("dd-MM-yyyy");
docOrder.replaceItemValue("Orderdatum",formatterDatumForField.format(currentDateForField));
to
docOrder.replaceItemValue("Orderdatum",currentDateForField);

Date formatting in a grid

I'm trying to display a date column in grid like this: "dd-mm-yyyy". In dbf table, the date is stored in this format: "YYYY-MM-DDThh:mm:ss" in a character field.
The grid is created from this cursor:
select id,beginningDate,endDate,cnp from doc ORDER BY id desc INTO CURSOR myCursor
I wish something like this:
select id,convert(beginningDate, Datetime,"dd-mm-yyyy"),endDate,cnp from doc ORDER BY id desc INTO CURSOR myCursor
Fox doesn't have a builtin function called convert(), nor can it handle your non-standard date/time string format directly.
A quick and dirty way to convert a string foo in the given format ("YYYY-MM-DDThh:mm:ss") to a date/time value is
ctot("^" + chrtran(foo, "T", " "))
The caret marks the input as the locale-independent standard format, which differs from the input format only by having a space instead of a 'T'.
You can extract the date portion from this via the ttod() function, or simply extract only the date portion from the string and convert that:
ctod("^" + left(foo, 10))
Fox's controls - including those in a grid - normally use the configured Windows system format (assuming that set("SYSFORMATS") == "ON"); you can override this by playing with the SET DATE command.
There seems to be no mask-based date formatting option as in most other languages. dtoc() and ttoc() don't take format strings, transform() takes a format string but blithely ignores it for date values.
I am with Tamar on this subject, you should have used a datetime field instead.
Since you are storing it like this anyway, you can 'convert' to datetime using the built-in cast function (or ttod(ctot()) in versions older than VFP9 - in either case you don't need to remove T character):
select id, ;
Cast(Cast("^"+beginningDate as datetime) as date) as beginningDate, ;
endDate,cnp ;
from doc ;
ORDER BY id desc ;
INTO CURSOR myCursor ;
nofilter
In grid or any other textbox control, you can control its display style using DateFormat property. ie:
* assuming it is Columns(2). 11 is DMY
thisform.myGrid.Columns(2).SetAll('DateFormat', 11)

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 to manipulate the date format in reminders

The date in reminder is US format ( mm/dd/yyyy) By default I guess. How to manipulate the collection of reminders and format the date to british format so that the listBox will show the reminders as below:
Begin Date ( in British Format or non-US format)
Content
MyReminders = ScheduledActionService.GetActions()
.Where(a => a.BeginTime.Date == Today);
foreach (Reminder r in MyReminders)
{
// How to change the date format to British in each of the reminder and display
in the listBox?
}
ReminderListBox.ItemsSource = MyReminders;
In the list Box :
&ltListBox Name="ReminderListBox" Margin="1,116,-2,4" &gt
&ltListBox.ItemTemplate&gt
&ltDataTemplate&gt
&ltGrid Background="Transparent" Margin="0,0,0,30"&gt
&ltStackPanel Orientation="Horizontal" &gt
&ltTextBlock Text="begin "/&gt
&ltTextBlock Text="{Binding BeginTime}" HorizontalAlignment="Right"/&gt
&lt/StackPanel&gt
&lt/Grid&gt
&lt/DataTemplate/&gt
&lt/ListBox.ItemTemplate/&gt
&lt/ListBox /&gt
problems : I dont want to set the date format in the listbox. I want to dynamically detect the locale and display the date Format base on the detected locale Ex Non-US format for Jpn, Kor, China
What does your listbox template look like? You should be able to make it pick the "right" date format for the culture using a format specifier of "d" (for short date) or "D" (for long date) ... and I'd expect you to be able to do that from XAML rather than changing anything else.
Note that the DateTime itself doesn't have a format - so it's not like you could set that value to be "in" UK format.
EDIT: I think you want:
{Binding BeginTime, StringFormat=d}
or if you want to force a specific format (which I don't recommend)
{Binding BeginTime, StringFormat=dd/MM/yyyy}

Resources