How to simplify this spreadsheet formula? - date

I am working on my personal financial spreadsheet, and I have one table that lists columns like: "Month","Income",Expense","Notes", and I am building a 2nd table to use to build a new chart so I can view Year over Year comparisons to the data (ie, I will get all of the Januarys' data charted next to each other to compare).
Here is the formula I'm using to transpose this data, but I know there has to be a better way, but my searching is failing me:
=arrayformula({
filter(B5:B64,MONTH(B5:B64)=1);
filter(B5:B64,MONTH(B5:B64)=2);
filter(B5:B64,MONTH(B5:B64)=3);
filter(B5:B64,MONTH(B5:B64)=4);
filter(B5:B64,MONTH(B5:B64)=5);
filter(B5:B64,MONTH(B5:B64)=6);
filter(B5:B64,MONTH(B5:B64)=7);
filter(B5:B64,MONTH(B5:B64)=8);
filter(B5:B64,MONTH(B5:B64)=9);
filter(B5:B64,MONTH(B5:B64)=10);
filter(B5:B64,MONTH(B5:B64)=11);
filter(B5:B64,MONTH(B5:B64)=12)
})
This just seems so unwieldy, though it does what I want. Any suggestions on how to simplify this a bit?
EDIT: for clarifications, I'm taking data that is like: Jan 2015; Feb 2015; Mar 2015; etc, and transposing it to: Jan 2015; Jan 2016; Jan 2017; Feb 2015; Feb 2016; Feb 2017 etc.

Formula
=ARRAY_CONSTRAIN(SORT({B5:B64,MONTH(A1:A24)},2,TRUE),COUNTA(B5:B64),1)
Explanation
{B2:B64,MONTH(B5:B64)} is a custom array of two columns, the input and a column of months.
The SORT function sorts the custom array
The ARRAY_CONSTRAIN function removes the column of months.

Related

DAX Expression for calculating end of every year

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:

Google Sheets | Return last Friday's date on Sat to Wed apart from Thu and Fri

I'm a bit rubbish on Google Sheets formulas... would anyone be so kind to tell me how to achieve this ?
I'd like to have a cell that returns the last Friday's date on Sat to Wed, and instead the current date for Thursdays and Fridays.
Is it possible ?
e.g. this coming days:
Sat to Wed returns Friday 12th of March
Thu 18th returns Thu 18th
Fri 19th return Fri 19th
... and so on.
Thanks!
There are many ways to accomplish this, but try this:
=IF((WEEKDAY(TODAY())=5)+(WEEKDAY(TODAY())=6),TODAY(),TODAY()-VLOOKUP(WEEKDAY(TODAY()),{7,1; 1,2; 2,3; 3,4; 4,5},2,FALSE))
This formula is based on the us default numbers for weekdays, where Sunday = 1. If this formula produces unexpected results, your locale may be one where Monday = 1. In this case, you'll need to adjust as follows:
=IF((WEEKDAY(TODAY())=4)+(WEEKDAY(TODAY())=5),TODAY(),TODAY()-VLOOKUP(WEEKDAY(TODAY()),{6,1; 7,2; 1,3; 2,4; 3,5},2,FALSE))
Other things to keep in mind:
The + in (WEEKDAY(TODAY())=5)+(WEEKDAY(TODAY())=6) means OR (where * would mean AND).
The VLOOKUP is looking up the weekday of TODAY() within a simple virtual array, which is formed between the curly brackets and which instructs how many days to subtract from TODAY() given the current weekday in order to arrive at the previous Friday.

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/

Table Calc - with IF statement? - Tableau

We have YTD data only. I've been trying to get a MTD running across the table.
So I thought I can run a Table calculation type - "Difference From" previous month.
This works well except for the first month of the year.
Jan MTD = Jan YTD NOT Jan YTD less Dec YTD
So January numbers are never right.
Is there a way to say, If month = "Jan" don't perform the table calc?
regards
Gem
You probably have something like
ZN(SUM([YTD])) - LOOKUP(ZN(SUM([YTD])),-1)
Then, for the first entry, LOOKUP() will return null. All you need to do is to return 0 instead, using ZN()
ZN(SUM([YTD])) - ZN(LOOKUP(ZN(SUM([YTD])),-1))
In case you don't know, you need to go to Edit Table Calculation..., then Edit Formula...
EDIT: I understand you have a bigger problem, that is your rolling sum restarts every year. In that case you really need an IF statement, but it is possible to overcome your "it's not always the same starting month" problem. You just need to check if that month is the first in your list or multiple of 12:
IIF(-FIRST()%12 = 0,
ZN(SUM([YTD])),
ZN(SUM([YTD])) - LOOKUP(ZN(SUM([YTD])), -1))
You just have to understand the FIRST() function. It will return the distance from the current position to the starting position. So, if you start in February, in August First() will return -6.
And the modulo operator will guarantee you restart every 12 months
Thanks Inox.
You are correct.
However I was intending more like this:
IIF(min(month([period_date]))=1,
ZN(SUM([YTD])),
ZN(SUM([YTD])) - LOOKUP(ZN(SUM([YTD])), -1))
Since the formula is an aggregate, I had to use "min" for the date. That was my problem using the IIF function, which was not apparent in my question.
This will produce MTD beyond 1 year, When it reaches the second January, it will not subtract Dec YTD.
Only problem I have now though is, if you begin the table on a month other than January... ie Feb.
Feb MTD is not Feb YTD??
(this is another problem, my report is to produce a rolling 12 month)... ie Feb to Jan, Mar to Feb)
So far, I'm just displaying 2 years to get over this, so forcing it to start on January. Not really a solution, but it gets the information across 12 months.

Crystal reports Crosstab date grouping.

I've created a report using the crosstab control which groups the data by date in columns. I'd like to take all of the dates that are earlier than the 1st of the current month (when the report is run) and combine them and the data being summarized into one column called Previous.
So instead of seeing something like this:
Oct Nov Dec Jan Feb Mar Apr May Jun Jul
I've see something like this:
Previous Jan Feb Mar Apr May Jun Jul
Is there a way of doing this in CR XI?
You would have to create a formula to do this (or probably two formulas one to get them in the correct order and another to display the correct string):
grouping formula: if {table.datefield} < currentdate then '0000' else cStr({table.datefield}, 'yyMM')
display formula: if {table.datefield} < currentdate then 'Previous' else cStr({table.datefield}, 'MMM')
ADDED SCREENSHOT
The answer was actually a modification of Lee's answer.
if {Command.ReqDate} < date(year({?StartDate}),month({?StartDate}),1) then dateadd('m',-1,{?StartDate}) else {Command.ReqDate}
use this to group on in the CT set to monthly
right click on the column header
select Format field,
select common tab
select display string formula
if currentfieldvalue < date(year({?StartDate}),month({?StartDate}),1) then 'previous'
else totext(currentfieldvalue,'MMM')