DAX Expression for calculating end of every year - date

I am looking for DAX expression to show me monthly figure for last financial years. Here is an example of the information;
The figure is accumulated since the starting of 31 Jan 2017 or earlier which I have no information. The data I have does not have a monthly view but Year to Date (YTD).
How could I structure the DAX so that it would be able to find out what is the figure for the month.
For example, Jan 2017 $2,000 , Feb 2017 $5000 (included figure from Jan 2017), March 2017 $8000 (included Jan 2017 and Feb 2017).
How can it be done to have the monthly view ?
Date............. Balance Sheet Amount.......View
31-Dec 2017................24,000.......................YTD *1
31-Jan 2018................24,010.......................YTD *1
28-Feb 2018................24,310.......................YTD *1
31-Dec 2018................30,000.......................YTD *2
31-Dec 2019................31,000.......................YTD *3
31-Dec 2020................40,000.......................YTD *4
30-June 2021................5,000.......................YTD *5

Let's say your current table does not contain previous balance, then it will be easier to obtain the current month movement with the following formula:
Current Month = Sheet1[YTD Bal] -
CALCULATE(SUM(Sheet1[YTD Bal]),
FILTER(Sheet1,Sheet1[Index] = EARLIER(Sheet1[Index]) - 1))
Before you start the dax calculation, you will need to add index column first and here is the output:

Related

Google sheets calculations for dates before 1900 - A possible solution

I am trying to do calculations without scripts. A solution can be to sum a far in the future date (31/12/9999) +1 and use that value to do calculations
Cell A1 = 1/2/1872 -> -10.194,00
Cell A2 = 31/12/9999 -> 2.958.465,00
Cell A3 = A1-A2+1 -> 2.948.270,00 -> 01/02/9972
I can adjust the year to a more confortable, year that is distant from edges (99999 and 1900) -> I use as offset 4000 which should preserve original leap year. A4: =DATE(YEAR(A3)-8100+4000;MONTH(A3);DAY(A3)) -> 01/02/5872
at this point I can use A4 to do most of calculations on dates and calculate back any adjusted date by using DATEVALUE()
This does of course take into consideration past dates that have issues with current official calentars; it seems that 19th century is ok.
I haven't tested/ported it to Excel.
Does anybody confirm it works?
the logic of your formula may be correct, but more factors must be considered when playing with the calendar as humanity likes to adjust even the rules of adjustment. here are a few examples:
the longest year in history: 46 BCE (708 AUC) lasting 445 days known as "the last year of confusion" as Ceasar added 3 more months (90 days) so that the next year (45 BCE) would start right after the winter solstice.
the shortest year in history: 1582 CE lasting 355 days where October had only 21 days (4th Oct. was followed by 15th Oct.) but also it depends where you are
because British Empire decided to reinvent the wheel by accepting the "1582-wheel" in the year 1752 CE where September had only 19 days (2nd Sep. was followed by 14th Sep.) resulting the year to have 355 days as well. however, if we are technical, the British Empire also had a year that lasted only 282 days because their "old" new year started on 25 March and not 1 January therefore the year 1751 CE started on 25th Mar and ended on 31st Dec. Turkey, for example, joined the "gregorian train" in 1st Jan 1927 CE after their December of 1926 CE had only 18 days so that year was long only 352 days. the latest country to adopt the gregorian calendar was Saudi Arabia in 2016 CE when they jumped from 1437 AH
the year zero: does not exist. 31st Dec. 1 BCE was followed by 1st Jan. 1 CE
753 AUC = 1 BCE
754 AUC = 1 CE
also, dude who invented this nonsense was born around 1223 AUC (470 CE) so that speaks for itself. this is important because offsetting DATEVALUE needs to be done in such a way that the calculation will not cross 0 eg. not drop bellow -693593:
=TO_DATE(-694324) - incorrect datevalue - 01/01/00-1
=TO_DATE(-693678) - incorrect datevalue - 08/10/0000
=TO_DATE(-693593) - 1st valid datevalue - 01/01/0001
=TO_DATE(35830290) - last valid datevalue - 31/12/99999
it's also worth mentioning that 25th Dec. 200 CE was not Friday on the Roman peninsula because people in that era used 8-day system
there are many calendar systems each with its own set of rules and up to this date there are still countries that do not recognize the gregorian calendar as a standard so if you want to re-live the year 2021 go to Ethiopia where today's 9 Oct. 2022 CE = 29 Mes. 2015 EC on the other hand if you prefer to live in the future try Nepal where today's 9 Oct. 2022 = 23 Ash. 2079 BS

How to display previous year totals into current year in Tableau??without creating parameter

I need to create a field of previous year total sales in the current year column.
Here is an example based on it being 2018 today: in 2018, it should be 2017 total sales(full year), in 2019, it should be 2018 Sales(jan-apr would be only months in may), and 2020 should be blank, as there are no data in 2019 yet, etc.
Use the calculation to make it as "Date-1".

PowerBI Datesbetween - Line Chart Visualisation

I am trying to plot on a line chart running data for 3 fiscal years. My fiscal year being 30 June and not 31 December
Data for Year 1 [1 July 2015 to 30 June 2016]
Data for Year 2 [1 July 2016 to 30 June 2017]
Data for Year 3 [1 July 2016 to 30 June 2018] This is the current year
The following is what I am hoping to achieve.
3 Year Chart
I am not certain how to achieve this.
I was thinking the following might be of some relevance
Revenue from Start = CALCULATE(Report[Revenue], DATESBETWEEN('Dates'[Date], BLANK(), LASTDATE('Dates'[Date])))
I have had it suggested to set up a new measure "Date2". But I really am not sure how to do this. Also given that I am after a third series would I then need to set up a "Date3"
For Date2 [and Date3 if applicable], how would this/these measures be coded, ie is this logical
Date2 = DATE(2015,07,01)
Date3 = DATE(2016,07,01)
Thanks for any help that can be offered. You will see from my question, I know what I want as an output, but have no idea how to really implement.
I would use the TOTALYTD function, e.g.
Revenue from Start = TOTALYTD ( [Revenue] , 'Dates'[Date] , "30 June 2018" )
This blog post is probably the best description of this and related functions:
https://www.sqlbi.com/articles/time-intelligence-in-power-bi-desktop/

Calculate performance vs LY with shifting month dates

I've tried so many times to solve this, but failed.
Question:
I help on a solution on how to calculate Current Year divided by last year in our Fiscal Year, month by month, where last years date differs from this years date
Scenario
I want to see how we performed on revenue January 2017 vs. January 2016
I select these date filters; YEAR = 2017 and Month = January. This will generate the dates 1st January to 31st January 2017
But, the dates for 2016, is not 1st January to 31st January
My company's logic is; Which DAY NAME was the 1st January of 2017 and find this first DAY NAME in January 2016 and then see which DATE this has.
Scenario Example:
2017 = 1 - 31 January and the DAY NAME for 1st January is "Sunday"
2016 = The date for the first Sunday in 2016 is 3rd January, therefore, the dates for January 2016 = 3 January - 2. February
My problem is how to make a formula that takes this year and divide that on last year's date range logic
What have I done?
First I created a formula; CALCULATE(SUM(Append1[SalesAmount]);SAMEPERIODLASTYEAR(Append1[Date]);ALL(Append1);FILTERS(Append1[Channel]))
This worked perfectly, but this just calculates 1-31 January 2017 / 1-31 January 2016 (calendar year, not fiscal year).
Googled through many, many Power BI post regarding Rolling months, DAX, DATE DAX and such, but i still haven't been able to come up with a solution.
Hope some of you can help me in the right direction!
Regards Erik
You can create a calculated column that gives the corresponding date from the previous year as follows:
DateLastYear =
VAR CurrDate = Append1[Date]
VAR LastYear = DATE(YEAR(CurrDate)-1,MONTH(CurrDate),DAY(CurrDate))
VAR Offset = MOD(WEEKDAY(CurrDate) - WEEKDAY(LastYear),7)
RETURN LastYear + Offset
Given this, you can create a calculated column that looks up the sales amount on those dates:
LastYearSalesAmount =
LOOKUPVALUE(Append1[SalesAmount],Append1[Date],Append1[DateLastYear])
At this point, you should be able to create your ratio as follows:
DIVIDE(SUM(Append1[SalesAmount]), SUM(Append1[LastYearSalesAmount]))

How to subtract two dates in Oracle and extract the year part from the difference?

My typical requirement is that I want to subtract two Dates cast as timestamp. The Minuend (First parameter) is the current date and the Subtrahend(second parameter) is stored separately as DD, MM and YYYY in three columns. The final output should be a discrete year as number. I am playing with something like :
SELECT (TO_DATE('05-DEC-2013') -
CASE LENGTH(CAND_DOB_DD)
WHEN 1 THEN
CAST(TO_DATE('0'||CAND_DOB_DD||'-'||CAND_DOB_MM||'- '||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP)
ELSE
CAST(TO_DATE(CAND_DOB_DD||'-'||CAND_DOB_MM||'-'||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP) / 365 END YEAR
FROM CANDIDATE
The Year part as Integer will be used for a very sensitive calculation. Please suggest if the above piece of SCRIPT will yield the desired result. Thanks in advance.
For most purposes you could just use the Months_Between() function to determine the number of months between two dates, and then divide by 12 etc.. Note that the number of months is an integer when comparing two dates that have the same day of the month or are both the last day of the month.
This is tricky when it comes to leap years.
Do you count 28th Feb 2015 to 28th Feb 2016 as exactly one year, when 28th Feb 2015 to 29th Feb 2016 is one day longer but plainly is a year?
What about 29th Feb 2016 to 28th Feb 2017, or 28th Feb 2016 to 28th Feb 2017?
Think carefully about these boundary cases, but Months_Between() is likely to be your best choice.