I have columns with year and month in alphabet in power BI. I want to convert this to date and connect the table with the date table.
When I convert the column to date by clicking on the "ABC" symbol next to the year then all the data is converted as 01/01/2020. I want to use the months in the period column and the day of the month can be any value. So, the second row should be 02/01/2020.
You can use the following custom column under Edit Queries > Add Column > Custom Column to create your date:
Related
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 report where I have sales data for end of every month. When I see the data in drop down ,I can see the end of month date , but when I have used slicer it shows the entire date range and not only the last day of the month. Is there any way in slicer through which I can just limit the date, so that only last day of month will be shown in slicer ?
If you have a dates table with a date field (named Date, in this case), you could add a column with this code: Table.AddColumn(PreviousStep, "EndOfMonth", each Date.EndOfMonth([Date]), type date)
Currently, I have a report that displays a series of data that I can filter on the basis of a "date slicer (type 'between')". This slicer works with as specifi column "i_date" because a date table (m_date[date]) is used for the slicer and the "i_date" (from another table "interv") is linked together (1:n relathions).
In this other table there is another date type column with the last modification date of the row (interv[modified]).
Now, when a period is selected with the date slicer, I'd like to show the data where interv[i_date] OR interv[modified] are inside the selected period.
How can I do that ?
Using a new column with the newest date between interv[i_date] OR interv[modified] is not a solution, because in this case if a row is modified after the period, it will not be shown. (because interv[i_date] < interv[modified])
solved with a second slicer simply
I have a column (monthyear) in the image below. I want to extract the Month and year from the column to put it in the new column. Note: In my dataset this information goes for every day of the year
So the new column would look like:
01/2020
01/2020
01/2020
etc.
In Power Query, use some of the date functions.
To get the year it will be
Date.Year([monthyear])
For the month, it will depend on how you want to format it. Using the month of June as an example:
To get 'Jun'
Date.ToText([monthyear],"MMM")
To get the month number in the format 06
Number.ToText(Date.Month([monthyear]), "00")
Just to get the number 6 it will be:
Date.Month([monthyear])
In DAX use the date functions
For year the calculated column will be:
YEAR([monthyear])
For the month:
MONTH([monthyear])
I would always do a much data transformation in Power Query when you can before it gets to the data model.
I have a date for when someone last bought something (lastbuy) and have an end date (lastday) column and I want to create a new column with this new value which will be a whole number. FYI, lastday and lastbuy are both Date/Time data types. I tried the following:
Column_name = DATEDIFF(lastday, lastbuy, day)
_______________________________________________
Column_name = COUNTX('Table_name', [lastday] - [lastbuy])