Could someone help me achieve the date logic as below:
I work for a fiscal year starting from Oct to Sep, once I finish the fiscal year and step into a new one I want the last month of last fiscal year's sales for reference until the end of new fiscal year. For example, now in Sep'17 the fiscal year ended but I want Sep'17 sales number to be shown in graph as reference until next Sep'18 later that I want Sep'18 number to be shown until Sep'19 and so on so forth.
The logic I have arrived is not a permanent solution as it requires editing once I step into Year 2018, it is as below:
IF YEAR([Invoice Date]) = YEAR(TODAY()) AND
DATEPART('month', [Invoice Date]) = 9 THEN [Sales] END
once I step into Year 2018, I need to make change to the above logic like:
IF YEAR([Invoice Date]) = YEAR(TODAY())**-1** AND
DATEPART('month', [Invoice Date]) = 9 THEN [Sales] END
Is there a way to achieve permanent solution without editing the logic?
Try this:
Create 2 calcualted fields for start date and end date, Where start date is september last year and end date is september current year.
Start Date:
DATEADD('month',-1,MAKEDATE(YEAR(TODAY())-1,MONTH(TODAY()),01 ) )
End Date:
DATEADD('month',-1,MAKEDATE(YEAR(TODAY()),MONTH(TODAY()),01 ) )
Now one more calcualted field which will create the filter and add the formula to filter to get the require data.
[Order Date]>=[Start Date] AND
[Order Date] <=[End Date]
Add to filter and then select True
Note: Here today function means start of the fiscal year that you need to manage.
Related
Here are my DAX formula's for YTD and QTD calculations.
Sales YTD := CALCULATE( [Total Sales], DATESYTD( 'Date'[Date] ) )
Sales QTD := CALCULATE( [Total Sales], DATESQTD( 'Date'[Date] ) )
The date table has dates from 01-01-2020 to 31-12-2040
What is the logic used by the DATESYTD and DATESQTD to derive the 1st date of the year (DATESYTD) and first date of the quarter (DATESQTD)? For example - How do I make it use the start date based on either of the following: calendar year, ISO year and fiscal year ?
For the DATESYTD, you can control the start of the year, by setting the year end date. The default with out this option will be the normal calendar year.
DATESYTD('Date'[Date]', "03-31")
This will start the YTD calculation from the "01-04" (Normal UK tax year)
For variations between Calendar, ISO and Fiscal years, you'll have to create individual measures, a switch based on a selection, or use a calculation group to drive your YTD measures.
DATESQTD doesn't have the same option. You'll need a well-formed calendar table for the other 'To Date' options.
Update: for week related start/end year, best to check out the dax patterns approach
I need to handle specific scenario in StorProc where I need to do date calculation excluding Sat & Sun. Weekends are holiday I need to handle the data within working days.
I have implemented below code
if (purchase_date = (trunc(sysdate)-2) or purchase_date = (trunc(sysdate)-1)) Then
specific operation
As I have to exclude Sat & Sun by above implementation is giving wrong results obliviously . For example if today is Monday it has to give me back the date of Friday, my implementation is giving me Saturday or Sunday. I need to calculation with dates for weekdays only. Any help would be appreciated.
Thanks
To compare it to the previous week day, you can use:
IF purchase_date = TRUNC(SYSDATE)
- CASE TRUNC(SYSDATE) - TRUNC(SYSDATE, 'IW')
WHEN 0 THEN 3
WHEN 6 THEN 2
ELSE 1
END
THEN
-- Do something
NULL;
END IF;
TRUNC(date_value) - TRUNC(date_value, 'IW') will count the number of days since the start of the ISO week (which is always midnight on Monday).
Note: Do not use TO_CHAR(date_value, 'D') in an international setting as it will give a different result depending on which country you run it in (the week starts on Friday in Bangladesh, Saturday in some Middle-Eastern countries, Sunday in America and Monday in most of Europe).
I need help on developing the expression for a parameter. What i need is:
That the report gives me data of the day before when it´s Tuesday, Wednesday, Thursday and Friday, and when it´s Monday that it gives me the data of the 3 days before (of Friday, Saturday and Sunday). How can i put that in an expression of the Parameter?
I usually have the date parameter that checks the current date and if it's Monday, subtract the extra two days.
=TODAY.AddDays(0 - IIF(TODAY.DayOfWeek.ToString = "Monday", 3, 1))
Then the query would use this as the starting date range and yesterday as the end.
WHERE MY_DATE BETWEEN #START_DATE AND CAST(GETDATE() - 1 AS DATE)
If the Date field has a timestamp then you'd need to convert that to a date.
WHERE CAST(MY_DATE AS DATE) BETWEEN #START_DATE AND CAST(GETDATE() - 1 AS DATE)
There is 2 dates column one is from date and second is to date .. and i want to get month difference from these two dates
like if
from date to date month difference
01-02-2019 02-02-2020 13
here 02 (feb) month 2019 till 02 (feb) moth 2020 so this means total 13 months covered..
i tried this but this shows wrong results
month(from date) - month(to date)
and i also try this
month([from date] - [to date])
I've been using the code below for this case.
It basically converts both dates to months and returns the difference.
First the Year component of the date is "converted" to months (year([to date]) * 12 part) and second adds the month number of the date (month([to date])
Num (
( (year([to date]) * 12) + month([to date]) )
- ( ((year([from date]) * 12) + month([from date])) ) + 1
)
UPDATE:
below is a screenshot of the result table with 2 expressions - including the +1 and excluding it. Depends how you want to calculate the full months +1 will "include" the last month as well
I'm working on Excel and Power Pivot and I'm trying to get the average sales between the last day of the past month and the last day of the current month, but I'm unable to get the right expression for it.
I have the "Credits" table and the "Calendar" table, both linked by the "Date" field.
So, this is what I have:
=CALCULATE ( AVERAGE(Credits[Sales] );
FILTER ( Calendar ;
Calendar[DateNum] >= VALUE(FORMAT(STARTOFMONTH(Calendar[Date])-1;"YYYYMMDD"))
&&
Calendar[DateNum] <= VALUE(FORMAT(ENDOFMONTH(Calendar[Date]);"YYYYMMDD"))))
I use that measure in a dynamic table along with the "Month" dimension, but it only shows the average for the full month, not taking into account the filters I'm trying to apply so that it also takes the last day from the previous month.
I think what's happening is that the month is still in your filter context.
Try FILTER( ALL(Calendar) ; instead.
I think you could probably also simplify your measure a bit. Maybe try something along these lines:
CALCULATE(
AVERAGE( Credits[Sales] );
DATESBETWEEN(
Calendar[Date];
STARTOFMONTH( Calendar[Date] ) - 1;
ENDOFMONTH( Calendar[Date] )
)
)