I would like to create a YearMonth column in Power BI and group data in this order in visual plot, say histogram.
I tried to create a duplicate of the datetime column MY_DATE(format: 05-10-2018 12:00:00 AM) and convert it to Year-Month format in the ColumnTools ribon:
Although in the column the format looks correct, eg., '2018-03', when I plot the graph after grouping by YearMonth it is repeating itself, ie., having multiple columns of 2018-07.
Then I tried creating YearMonth with:
YearMonthText = YEAR(Table[MY_DATE]) & "-" & MONTH(Table[MY_DATE])
This looks good in both table column and was able to aggregate data when grouped by YearMonth, however, the table is not in chronological order, eg.:
2020-10 2020-11 2020-12 2020-7 2020-8 2020-9 2021-1 2021-2 ...
How can I get the plot to show data in chronological order?
Worked for me:
First, use:
YearMonthText = YEAR(Table[MY_DATE]) & "-" & MONTH(Table[MY_DATE])
to get YearMonth in text format(eg., 2018-3).
Then, convert Data type to Date type in ColumnTools ribon.
Related
I am working on a project, in Snowflake, that requires me to combine pest & weather data tables, but the opposing tables do not share a common column. My solution has been to create a view that extracts the year from the Pest Table dates, format ex.
CREATION_DATE: 03/26/2020 09:11:15 PM,
to match the YEAR column in the Weather tables, format ex.
DATEYEAR: 2021.
However, I have come to find that the dates in the pest report are VARCHAR as opposed to traditional date/datetime values. Is there a way to pull just the Year out the VARCHAR date value? Additional information: I cannot change the tables themselves, I will need to create a view that preserves all other columns and adds a new "DATEYEAR" column.
Yes , we can and below is working example:
create table test (dt string );
insert into test(dt) values ('01/04/2022');
Select dt, DATE_PART( year, dt::date) from test
To make it easy, you can split the string into an array and take the third member of the array (using 2 since arrays are 0 based):
select strtok_to_array('03/26/2020', '/')[2]::int as MY_YEAR;
I have a column containing dates in the following format: "28-SEP-2018 12.40.00", does anyone know how to extract the month and year from the date in a new column (i.e. Sep- 2018), via producing a measure.
#navee1990 the measure to extract the date and year is as follows
= MONTH([date] & YEAR([date])
Or the long way
CONCATENATE(MONTH([date]),YEAR([date]))
Assuming the type of the column is Text and you want the new values to be displayed as SEP-2018 rather than 09-2018:
You would need to create a new column with DAX as c1 = MID(Table2[Column1],4,8)
In case if the column is of type: DateTime ; then use the below DAX for new column :FORMAT(Table2[Column1],"MMM-YYYY")
New Date =FORMAT([date], "MMM") & "-" & YEAR([date])
This would give you a column with text data type. You can further create a column to sort the New Date column as per calendar chronology.
I need help to convert Numbers into date format using Power Query Editor in either Excel or PowerBI
The date appears in number form like this 930101 and I want to convert it to normal Uk date format
Not sure which one is month and which one is date among "0101" in your string. But you can handle this your self and follow this below steps for get your required output in Power Query Editor-
First, split your string value using fixed 2 character and your data will be divide into 3 column now. define which one is Year, Month and Day.
Now, merge those 3 column maintain the UK pattern DD/MM/YY using a separator "/" and you will get a string like "01/01/93".
Finally, create a custom column using the below code-
Date.From([Merged],"en-GB")
Here is the final output-
In the above image, you can see the date in still US format just because of my Laptop's locally setup.
I'm working on making a replica of sheet1 on to another sheet2 (same document), and query() worked fine until the column i want to filter are formula cells (LONG ones each with query, match, etc).
What i want to do is filter the rows in sheet1 where the event date in column M is upcoming (there are more filter conditions but just to simplify this is the main problem).
I don't want the rows where the date is either empty, in the past (various date formats), or where the formula give a result of empty string "".
The formulas i've tried (which gives error) - note i'm just selecting 2 columns for testing:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND DATEVALUE(M)>TODAY() ",0)
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M>TODAY() ",0)
This formula doesn't give error but doesnt show correct data - shows all data except Jan 2017 - August 7 2017:
=FILTER(sheet1!A3:N, sheet1!I3:I="Singapore", sheet1!M3:M>TODAY())
This formula gives empty output:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M='22 August' ",0)
There's no today() in Query. Use now() instead:
=query(sheet1!A3:N, " select I,M where I = 'Singapore' AND M > now() ",0)
Or if you want now() without time(equivalent to TODAY()), use:
todate(now())
For this to work, provided you have all the correct dates in M in any format, which Google sheets recognises (i.e., the formula bar shows the correct date or time) regardless of the actual string. If not, You should manually convert all those remaining dates to correct format. The correct format of date to be entered in the query formula is date 'yyyy-mm-dd'. It doesn't matter what format the date is in sheets ( as long as Google sheets recognises this), but the actual formula must only contain date in this format for comparison. For example , to find all dates less than 31,August, 2017,
=query(A2:B6, "select A where A < date '2017-08-31'")
You can use this to figure out all the dates, which Google doesn't recognise: N1:
M:M*1
If you get an error in the helper column N, then those dates are not recognised. Even if you did not get error, it is possible that Google sheets mis-recognizes the date. There is also a more specific function:
=ARRAYFORMULA(ISDATE(M:M))
References:
Scalar functions
I have a simple HQL statement which works. I want to be able to count the occurrence's by Year or by Month. The data Quality is not good,and the incorporationdate column is held as a varchar100 and contains free flowing text and nulls
So I cannot use Substring or YEAR as I need to only perform a extract on the format mm/dd/yyyy to pull out the Year or month. Ideally I would like to create a View and create 2 new Columns , one to show the year and one to show the month this would be the perfect scenario.
select
incorporationdate, count(incorporationdate) from default.chjp2
group by companynumber,incorporationdate
===================================================
Regards
JP
you could use if and test any condition you want before using substring:
select if(date is not null and date rlike '^\d{2}\/\d{2}\/\d{4}$', substr(7),null)