I have colunm where date format DD/MM/YYYY I want to extract only month name like this MMM using power query and a calculated column
Example:
15/01/2021 becomes Jan
You can add a new column like below :
Month = Format([YourDate],”MMM”)
Or using a custom column :
= Table.AddColumn(#"Changed Type", "NewColumn", each DateTime.ToText([YourDate], "MMM"), type text)
Looks like you are quite new to PowerQuery, you can use the editor, or add the following to your M Script.
= Table.AddColumn(#"Renamed Columns2", "Custom", each Date.ToText([Date], "MMM"))
Add a custom column
open Power Query Editor -> click on Column from Examples -> Choose From Selection option
Select the date column from which you want to extract and then rename the new column as month.
Now, for example, if your first date in the date column is "15/01/2021" then type as jan and type the same in the second column as well as "jan" if the date is from the month of january then click on the screen. so all the values will become as "jan".
then you have to find a row which contains another month like "february" in your date column, then type "feb" and then click somewhere on the screen
you should get the result you wanted. :)
p.s. If this (or another) answer helps you, please take a moment to "accept" the answer that helped by clicking on the check mark beside the answer to toggle it from "greyed out" to "filled in".
Related
i need help on cleaning this data. Currently I've no idea to clean this kind of data. I want to clean based on month and total per supplier. Thanks
Select the first 2 columns [No] and [Supplier]
On the tab Transform drop down Unpivot Columns and click on Unpipot Other Columns
This converts your wide pivot table into a long, stacked format that is ideal for further processing.
Another way you can achieve this is
Select all the date columns.
Click on the transform tab, under any column section, click on unpivot only selected columns
Kindly rename the Attribute column to date
If you need to split the date column into month and year
4. on the transform tab, under the text column section, click on Split Column, select "by delimiter" on the dialog box, select split at the left-most delimiter and click ok.
You will have your month and year columns as shown below
if your value column holds figure for amount/money you can transform the data type and replace the null values with zero using the replace values function when you right-click on the values column.
I hope this helps
I pulled data into Power BI from a SQL query which returns only the order year in one of the columns. In Power BI I formatted the column as "Data type Date" and "Date time format 2001(yyyy)", but when I pull that column into a table in Power BI, it's clearly calculating 2020 and 2021 as the number of days from 1/1/1900 (like excel) because it shows the year as 1905 for both when inserting this column into a visual, instead of years 2020 and 2021.
How can I format this column as the year 2020 and 2021?
Thank you,
You can convert it in the data source, or you can add a custom column in Power Query with M, or a calculated column in the model with DAX. If your data is not too much, it doesn't really matter where you will do that, but the general recommendation is to do that as close to the data source as you can (i.e. if you can, add it to your query, or if you can't add a calculated column).
The data source option needs a column in your query, which can be added with expression like this (this one uses DATEFROMPARTS T-SQL command, if you are using another database, you will have to change it):
DATEFROMPARTS(ExistingYearOnlyColumn, 1, 1)
Or click Transform data to open Power Query Editor and click Add Column -> Custom Column:
and use #date to create the date:
The last option is to create a calculated column in DAX, by right-clicking on your table and selecting New column:
And use DATE DAX function in an expression like this:
DateColumn = DATE([ExistingYearOnlyColumn], 1, 1)
I have a calendar table in Power BI linked to two other tables, one with occupancy by date and another with predicted occupancy by date. The second table goes well into the future.
I want the report to have a rolling 15 day range, 7 days prior to today and 7 days into the future. I tried to create a custom column using:
ReportRange = IF(DATESBETWEEN (Calendar[SQL_Date], (TODAY()-7), (TODAY()+7)),1,0)
I get a response "No syntax errors have been detected."
But when I click "OK", I get a yellow bar/warning:
"Expression.Error: The name 'IF' wasn't recognized. Make sure it's spelled correctly."
Can anyone help with this?
Thanks!
You need to write custom columns in the query editor in M code, not DAX.
Something like this may work:
if Date.IsInPreviousNDays([SQL_Date], 7) and Date.IsInNextNDays([SQL_Date], 7)
then 1
else 0
You may prefer to use relative date filtering instead though.
You are attempting to use a PowerQuery M Language column through the custom column editor. This will not work in M. You will need to create a measure in DAX to do the calculation.
In your DAX you can use DatesBetween, as per this example:
=CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), DATESBETWEEN(DateTime[DateKey],
DATE(2007,6,1),
DATE(2007,8,31)
))
You can use the TODAY keyword to work calculations off the current date.
for "rolling" filters i found it very useful to build generic offset columns for day/week/month/quarter into your date table. with that you can easy filter a visual e.g. with "week offset" > 1 and "week offset" <-1 to get rolling 2 weeks views... Detailed howto can be find here: https://radacad.com/offset-columns-for-the-date-table-flexibility-in-relative-date-filtering-for-power-bi
If you just want to filter the data coming in to the report, you can use a filter.
You can do this in the Advanced Editor, sample below.
let
Source = BillingData,
#"Removed Other Columns" = Table.SelectColumns(Source,{"Date"}),
#"Changed Type" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Date", type date}}),
#"Removed Duplicates" = Table.Distinct(#"Changed Type"),
#"Filtered Rows" = Table.SelectRows(#"Removed Duplicates", each Date.IsInPreviousNDays(Date.AddDays(DateTime.LocalNow(), 7), 14))
in
#"Filtered Rows"
I started with the standard date filter and customised it using the advanced editor to add 7 days and then subtract 14.
I had added new table to my Power Bi file that contains a column with date with the following format: dd/MM/yyyy for example: 17/08/2017.
In power Bi this column is Text type, and when I try to convert to date it came with the following error:
DataFormat.Error: We couldn't parse the input provided as a Date value.
Details:
17/08/2017
how can I change its type or format this text on new column and change the type if possible?
First try altering the Regional Settings for the Current File to a country where dd/MM/yyyy is the standard date format. Like the Netherlands (or maybe your own country).
Choose [Options and settings > Options] on the File-tab. When you're done, refresh.
If changing the settings doesn't work for you, you can use the Power Query Editor to split the date column and then merge in the correct order. Perform the following steps:
Select the date column and use Split Column (Transform tab). Split by delimiter [/] and select [Each occurance of the delimiter]
Merge the three columns again by using Merge Columns. The columns will merge in the order that you select them. For the separator choose custom and type /
Change the datatype to Date
This part of the script should look somthing like this:
#"Split Column by Delimiter" = Table.SplitColumn(Table.TransformColumnTypes(#"Previous step", {{"Date", type text}}, "en-US"), "Date", Splitter.SplitTextByDelimiter("/", QuoteStyle.Csv), {"Date.1", "Date.2", "Date.3"}),
#"Merged Columns2" = Table.CombineColumns(#"Split Column by Delimiter",{"Date.2", "Date.1", "Date.3"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Merged"),
#"Changed Type5" = Table.TransformColumnTypes(#"Merged Columns2",{{"Merged", type date}})
I need to create an dynamic list of months from current month back to 10 months ago using Power Query M. I found that there is only List.Dates to create a list of date between specific duration but no function help to create the months list.
Could anybody has some way to help?
Thanks
Not sure what you are looking for, but the following code will give you 3 columns for the previous 10 months and the current month (at last refresh, you need to refresh each month):
Start of Month (date)
End of Month (date)
Name of Month in Vietnamese (text)
let
Source = Table.FromList({-10..0}, each{_}),
AddedStartOfMonth = Table.AddColumn(Source, "StartOfMonth", each Date.StartOfMonth(Date.AddMonths(Date.From(DateTime.LocalNow()),[Column1])), type date),
AddedEndOfMonth = Table.AddColumn(AddedStartOfMonth, "EndOfMonth", each Date.EndOfMonth([StartOfMonth]), type date),
AddedNameOfMonthInVietnamese = Table.AddColumn(AddedEndOfMonth, "MonthName", each Date.MonthName([StartOfMonth],"vi-VN"), type text),
RemovedColumn = Table.RemoveColumns(AddedNameOfMonthInVietnamese,{"Column1"})
in
RemovedColumn
Assuming you want to achieve a filter, I would just hit the Filter drop-down button for your date column in the Query Editor, then choose Date/Time Filters / In the Previous / 10 / months. This will generate something like this:
Filtered Rows = Table.SelectRows(Source, each Date.IsInPreviousNMonths([My Date], 10))