PowerBI Date column - 1 year with static date - powerbi

My fiscal year start is in the past. I have a date column and I have the code below in a separate calculated column.
Year Start = DATE(YEAR(sales[close_date].[Year])-1,MONTH(12),DAY(22))
On the first row as an example, I have 31/07/2016 but in this column I am getting 21/01/1904
Could someone explain why?

You can check this below code-
Year Start = DATE(sales[close_date].[Year] -1, 12,22)

Related

How to Get Custom Week Desc in DAX

Basis on below data I want to add a calculated column with Week Description
I've done it in excel by typing it manually.
Also my week is starting from Thursday and ends on Wednesday hence I've Used this function to get the weekday WEEKDAY('Calendar'[date],14)
Requesting you to help me with a dax code which can be used to create a new calculated column with week information as shown below in third column.
The logic would be : If the date is current week then the value will be "This Week" else if the
date is in last week then "This Week -1" else if the date is in last to last week then "This Week - 2" and so on.
The weekday can be calculated as following:
Weekday = WEEKDAY([Date] + 3)
We do a shift of 3 days to make Thursday the start of the week
Next, we get the WeekDesc in two steps, frist we calculate the difference between now and the date in weeks and as second step we use an if statement to create the correct sting (and logic).
WeerDesc =
var weeksPast = DATEDIFF(now(), [Date] + 3,WEEK)
return if ( weeksPast = 0, "This Week", "This Week" & weeksPast)
As you can see you can use variables in your DAX, I would recommend using them to keep the overview.
Enjoy
We can do this also in this way (as a measure if you need only label to display on rows):
DayOfWeek = WEEKDAY(SELECTEDVALUE('CAL'[Date]),14)
DiffToToday = DATEDIFF(SELECTEDVALUE('CAL'[Date]),TODAY(),DAY)
Label = CONCATENATE("This Week", (DIVIDE( CAL[DiffToToday] + CAL[DayOfWeek],7) -1) *-1 )
Of course, we can do all steps in one measure.

Last Year vs Current Selected Year

I have been creating a dashboard in which I am trying to showing current Selected year vs last year analysis. Please see the below image :
As you see in the above image, 2020 year selected from the slicer and 2020 sales is 4.30M.
Expectation : I want to show the last year difference with Arrow sign means if the current year sales is greater than last year than "Green upper arrow" and if the last year sales greater than current year then "Red down arrow".
Thing I Tried : I have created a DAX, but it not showing any value to me :
Previous Year Sales = CALCULATE(sum(Orders[Sales]),PREVIOUSYEAR(Orders[Order Date]))
Option 2 : I have also tried this one (it show me value but desired results):
same period last year = CALCULATE(Sum(Orders[Sales]),SAMEPERIODLASTYEAR(Orders[Order Date]))
Expected Output ( Current Year vs last year percentage with Arrow sign) :
Sample data link :
http://www.cse.ohio-state.edu/~hwshen/Melbourne/Data/Superstore.xlsx
How can I achieve the above ?
Thanks
The percentage should be straight foward. Keep in mind you need a DATE TABLE or use the automatic datetime created by power bi, for that you need to reference it with ".[Date]"
same period last year = CALCULATE(Sum(Orders[Sales]),SAMEPERIODLASTYEAR(Orders[Order Date].[Date]))
Sales YoY % =
VAR _ly = [same period last year]
RETURN
DIVIDE(_ly-Sum(Orders[Sales]),_ly)
Format you [Sales YoY %] measure as a percentage.
The visual part you can do it multiple ways, cards, HTML, KPIs Visuals or Table/Matrix conditional formating.

How to extract Month and Year from column in PowerBI powerquery

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.

Power BI - setup day 1 based on value in another column

I have table in Power BI with following columns: Country, Date and event. I would like to add measure or new column if needed with 'Start Day'. 'Start Day' assignes value '1' at the first day that value greater than 0 apears in column 'event' and starts counting days from this date. In example below for country UK value 1 in column 'event' apears on 19/03/2020 and in column 'Start Day' value 1 is assigned. Next date 20/03/2020 has value 2 assigned and so on. What is the best way to do this in Power BI?
Robert
You need to create an extra column as this is static data.
You can do this by first getting the start date of that country and then take the datediff between the dates.
In the CALCULATE function, I get all rows where the country is equal and where the event = 0. From those rows, I get the max date (firstD). This was the most important step as we can now use the DATEDIFF to calculate the days.
I used the max function once more because you want to have 0 in the rows before the startdate.
Start Day =
var country = events[Country]
var firstD = CALCULATE(MAX(events[Date]);FILTER(events;events[Country] = country && events[event]=0))
return max(DATEDIFF(firstD;events[Date];DAY);0)

Calculated Column to get previous year

I have a Date table and I want to create a calculated column that gives me the date of the previous year. For example, if the date is 2018 then Previous_Year column should be 2017.
Current Column is [_Year]
New Calculated Column is [Previous_Year]
In Dax this is what I have [Previous_Year]= DATE(YEAR([_Year]-1,YEAR))
thanks
Try something like this:
Previous_Year = YEAR('Datetable'[_Year])-1)
I am presuming that [_Year] holds a datevalue and that you want the year of that date minus 1.