How to extract Month and Year from column in PowerBI powerquery - powerbi

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.

Related

Power BI previous year and Previous month in same column date hierarchy

I want to get the revenue data by the department to see the current month vs previous month comparison, what I also want is that when the data is rolled up to year it should show me the previous year data, which I am not able to achieve.
enter image description here
If you look at the image I am getting the previous month sales with respect to the current month but for year 2021 I see the data for December 2020 but I need 1,09.900 instead.
I tried Summarize function and other date function but am not able to achieve the data in required format as below
enter image description here

How to create a YTD using fiscal year / financial year

Apologises if this question has already been raised but I'm struggling with my data model to create a rolling total / YTD sales using fiscal years.
I know PowerBI/DAX is great using calendar Jan-Dec dates but how do you amend this if your financial year begins in March-April instead?
When I created my calendar table, I used the CALENDEARAUTO() which gave me a column of dates from Jan to Dec as expected and when I change the function to CALENDERAUTO(3), my date column begins from March to April which makes sense.
However, if I use the CALCULATE and DATESYTD functions to sum the total sales column and choose the date column as described above, the result looks like:
Actual YTD = CALCULATE(sum('spend'[Actual]),DATESYTD('Fiscal Year Table'[Date],"03-31"))
What do I need to do exactly for it work in this exact date format?
Many thanks
Hash

In Power bi Date slicer can we only show the end of month dates instead of showing all the dates?

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)

How to convert alphabet in date in power BI

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:

How to calculate last 4 any weekdays sales in power bi

I want to calculate last 4 any weekdays total sales.Based on filter max date.
Example: I have 2 filter
1. Date range(From -To)
2. Week Day(Like Mon,Tue Etc.)
I need total sales for last 4 Monday or Tuesday (as per above filter ).And Last 4 weekdays will be calculated based on To-date in filter.
Like To-date is 31-Dec'18 then last 4 Tuesday will be 4,11,18,25 Dec.
Thanks in advance for the help.
Nitika, the best way to do that is creating another table to put a 'Dimension' with dates, int that you can put, weekday, day, holiday, year, month...
Something like that:
Do You Need a Date Dimension?
Why use a Date Dimension Table in a Data Warehouse
Doing that you can reference your atual date with this table, and get just the weekday that you are looking for