Excel to specify the month to report the data - excel

Using excel, is it possible to specify the month to report in a cell?
For example, excel would need to report the latest reported sales, if its available. If the month of February sales is not available, then it will report January sales. Likewise, if March sales is available, it would report the sales in March.
How do you write this formulae in a cell in excel? If its not possible to write such a formuale, can we write a vba to do this?

If you mean you have a list of sales entries and want the sales for the last month in the data, you could write one formula to get the latest month. If months are in A you could write: =month(max(A1:A99999))
Note if you have multiple years data, you need to pull the year too or get bounding dates. You can then sum sales using an array formula like assuming the result of the first action is in D1 and sales are in B: {=sum(if(month(A1:A999999)=D1,B1:B999999,0))}
If you have incremental updates during the month, this will return month to date data. If you need data for the last full month, you can use another array formula to get the maximum month where the date is the last day of the month.

If the cells for future data in B1:B12 are blank then you just need to extract the last number in B1:B12 don't you? If so then try
=LOOKUP(9.99E+307,B1:B12)

You can use the OFFSET function to select specific data based on the month.
Insert a formula to calculate the current month (or just type in the month number)
=MONTH(TODAY())
The formula to select the current months of sales data
=SUM(OFFSET(B1,MONTH(TODAY()),0,1,1))
Have a look at the help in Excel on the OFFSET function. It can be used to select a range of data. For example, to return data from the start of the year to the current month the formula would be:
=SUM(OFFSET(B1,1,0,MONTH(TODAY()),1))
If the current month does not contain data yet, you can test to see if a value is returned and revert to the prior month if there is no data.
=IF(SUM(OFFSET(B1,B16,0,1,1))=0,SUM(OFFSET(B1,B16-1,0,1,1),SUM(OFFSET(B1,B16,0,1,1))))

I found this answer:
=IF(B12<>0,B12,IF(B11<>0,B11,IF(B10<>0,B10,IF(B9<>0,B9,IF(B8<>0,B8,IF(B7<>0,B7,IF(B6<>0,B6,IF(B5<>0,B5,IF(B4<>0,B4,IF(B3<>0,B3,IF(B2<>0,B2,IF(B1<>0,B1,0))))))))))))
This formulae solves the problem of picking up the latest available data.

Related

calculate sales for previous dates (mid-month and end month) using DAX

I am very new to DAX and i want sum of sales for the previous months. As you can see, the dates are : The 15th of every month and the last day of every month. Can anyone please help me?
I want when i use the date as a filters , when i chose a date, i want the measure to give me the results of the previous date.
Have you tried making a calculated column that shows the "previous date" for each date. If that is successful then possibly you could return the result using the date from the "previous date" calculated column when the row with a date was selected.
OK. Thanks for posting this. Working on it has been very instructive. I've attached a copy of my power bi file and a pdf
this may not be a solution you can use... it does show both amounts received during the month and the total for the month (months are displayed as numbers)
The core trick I used was to create 2 calculated columns for each row, one for the 15th the other for the end of the month. I populated them with a zero or the amount in the row depending on what the date field in the row looked like. that gave me amounts i could summarize.
https://drive.google.com/file/d/1hdM5QKonEft4sYk2yyD0JLlXJcEb3baU/view?usp=sharing

How to select the last day of selected months in daily data in EXCEL

I have daily data from 01-Jan-2005 till 29-Dec-2017. I want for each year to select the last day of March, June, September, and December, alongside their respective data. Part of the data:
Date Variable
30-Mar-2005 1.2943
31-Mar-2005 1.2964
1-Apr-2005 1.2959
4-Apr-2005 1.2883
5-Apr-2005 1.281
I.E: For 2005, I want the dates of 31-March-2005, 30-June-2005, 30-September-2005, and 30-Dec-2005. Desired output:
Date Variable
31-Mar-2005 1.2964
30-Jun-2005 1.9859
30-Sep-2005 1.2233
30-Dec-2005 1.2814
I currently have the build in excel formulas (i haven't installed any other plug-ins etc).
More specifically: on the left i have the data, and on the right the desired output.
Not sure if this is going to work to you, but anyways.
Looks like you always look at the last day of months March, June, September and December on a specific year (in example, 2005).
But you are not looking for the last natural day of each month. You want the last day of each month that appears in your data (in example, that explains why you use 30 december 2005 instead of 31, because there is no 31).
In Excel, dates are numbers. The more you go in the future, a bigger number is related. Knowing this, you can get the date for each month just looking the MAX value of a range of dates.
But first, you need to define the range of dates, using 2 conditions:
Month of date must be March, June, September and December
You want dates for a specific year (in example, 2005).
To get this, you need an array formula. My formula gets the max day of a specific month and year. To test it, in my Excel I did a dates series, starting in 01/01/2005 and done in 31/12/2017. I deleted manually 31/12/2005 because that date has no data.
In cell I4, just type the year you want to check. The formula will get he last day of months March, June, September and December of that year.
My array formula is:
=MAX(IF(MONTH(IF(YEAR($A$4:$A$4750)=$I$4;$A$4:$A$4750))=3;$A$4:$A$4750))
IMPORTANT!: Because it is an array formula, you will need to type it
as usual, and then, instead of pressing Enter press
CTRL+SHIFT+ENTER
You need 4 times this formula. Just change the 3 (March) for the number of the month you need (6,9 and 12).
Now that you have the dates, you just need a VlookUp to get the value you want.
=VLOOKUP(G5;$A$4:$B$4750;2;false)
If I change the year value, i get those new values:
If you want to check the file. I uploaded an example to Gdrive, so you can download if you want.Download
Anyways, try to adapt this formulas to your needs.
I converted a list of Euro conversions into a Table and used structured references. But you can use normal range references if you prefer.
In some other table, enter the following formula, where $A$45 refers to the first quarter ending date in your data table.
F2: =IF(EOMONTH($A$45,(ROWS($1:1)-1)*3)>MAX(Table1[Date]),"",LOOKUP(2,1/(EOMONTH($A$45,(ROWS($1:1)-1)*3)>=Table1[Date]),Table1[Date]))
In the adjacent column, enter the formula:
G2: =IFERROR(VLOOKUP(F3,Table1,2,FALSE),"")
And fill down until you get blanks.
(in my sample table, the last date is 1/27/2006 so the last included "End date" is 12/30/2005, there being no data for 12/31/2005)
So, there are two cases
When you have the exact last days of the month. (Its simpler).
I had a fortnightly data. I adopted this simple and innovative method. From all the dates, I first extracted the day using Day() function. for example, Day(A1). (Remember, while doing this, do not delete your original date column. Do it in a separate column as this would help you match the dates later).
Then I sorted the data using the Day column, just constructed before, in decreasing order. This would place all end dates at first. And then deleted the starting dates which were at bottom. So, now I am left with only end dates but obviously months are not in order.
So, create another column extracting just the month and year from the original date column using =MONTH(A1) & "/" & YEAR(A1). Sort the data using this column. And, you are good to go!
When you do not have the exact last days, but maximum dates like the one shown above in picture.
In this, while deleting the initial dates, you would have to take care of which date on-wards you need to delete.
For example, I deleted day 17 on-wards of months with 31 days (including day 17) and day 16 on-wards of months with 30 days (if present) because if there was this date, suppose, 18 April 2018, then this would be the last day of the month as I had a fortnightly data.

Calculate monthly average from daily data without PivotTable

My worksheet contains two columns: column A contains the date in the format dd/mm/yyyy and column B contains the daily data. From the daily data I have to generate the monthly average for each month without a PivotTable. Some of the days contain no data at all. I cannot use a PivotTable as I have to use the monthly average to identify outliers in the daily data at a later stage.
For this example it's important that I don't use a PivotTable and that I can generate the monthly average data for any month and year in my list. The solution can be an Excel formula or VBA.
Assuming you have the months in column D enter this formula in E2 and copy till last month
=AVERAGEIFS($B$1:$B$62,$A$1:$A$62,">="&D2,$A$1:$A$62,"<="&EOMONTH(D2,0))
Some of the days contain no data at all.
In case this means that there are no row for some dates and you want to calculate average based on full month than you can use the below formula:
Continuing with example given by EEM
=SUMIFS($B$1:$B$62,$A$1:$A$62,">="&D2,$A$1:$A$62,"<="&EOMONTH(D2,0))/DAY(EOMONTH(D2,0))
In case Daily Data contains some #N/A, one can add a additional criteria to skip non number data:
=AVERAGEIFS($B$1:$B$62,$A$1:$A$62,">="&D2,$A$1:$A$62,"<="&EOMONTH(D2,0),$B$1:$B$62,"<10E69")
Given a single date you can calculate both the End of the Month and the First of the Month for that date. Assume any given date is in E4:
For the End of the Month
=EOMONTH(E4,0)
For the First of the Month
=EOMONTH(EDATE(E4,-1),0)+1
If you place a date, any date, of the month you want to review into cell E4 the two above code snipets will give you and last and first days of the month. EDATE allows you to add and subtract whole numbers to change the month. We take one month away from the current month, found within the date in cell E4, and then find the end of the month and add a one to it to become the first day of the next month. It will work with any date. The below example shows grade averages over a month referencing any given date within the month.
Pic of the above Excel example
=AVERAGEIFS(C2:C11, B2:B11,">=" & EOMONTH(EDATE(E4,-1),0)+1, B2:B11,"<=" &EOMONTH(E4,0), A2:A11, E2)

Show data of current month in single row

I've got a table in Excel 2013 with several data of all the year group by month (each month has his own row), and I'd like to have a single row that shows the date of the current month.
Any idea how can I implement this?
Thanks!
use month(now()) to get the current month, format so that it matches the way your month labels are stored and then use vlookup to display the data (one vlookup per each data column)

Generate trend graph in excel

I encountered a practical problem that can be simplified as follows:
My excel sheet has a single column which is the date I had a beer can. It can repeat based on the number of beers cans I had a day. (eg. I had three beers on 5/9/2012) I need to generate the trend of my beer consumption per week. How can I do it in excel?
**Date of beer**
5/9/2012
5/9/2012
5/9/2012
5/12/2012
...
7/3/2012
You could make a pivot table. Date as a row field, Count of Date (i.e., count of beers) as a data field. Group the row field Date by 7 days to get weekly totals.
You'd probably be better off with a two column spreadsheet. Column A = Date; Column B = Number of cans. Then you could easily just make a line graph from that.
If you already have a large amount of data in your format you can use excel's subtotal function to create the two column format for you.
First i would put a formula in to get a week number for each date, and then use a count if for each week of the year.
This formula will assign each day of the year the week number of the year it falls in. Put this in each cell next to your dates.
=IFERROR(1+INT((AF12-DATE(YEAR(AF12+4-WEEKDAY(AF12+6)),1,5)+WEEKDAY(DATE(YEAR(AF12+4-WEEKDAY(AF12+6)),1,3)))/7),0)
Once that is done create a column of numbers 1-52 (53 for leap year) and do
=countif(rangeofcalcdweeknumbers,week1to52)
and copy that down for all 52 or 53 weeks
Then make a graph based on the final two columns

Resources