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

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

Related

Increment Date by One Day in Formula - Excel

I want to have separate two columns that each row has a date, and another row containing total sale of the date.
I want my formula to increment the date by a day and automatically sum every transactions in that day.
I apologize if my explanation is awful.
Use Sumif To Sum Value See Bellow Mention Screenshot
=SUMIF(A:B,D2,B:B)

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)

Convert date in Excel to its respective week of the month

Hopeful you can help me out.
I have an Excel spreadsheet open. The spreadsheet has two columns that I need assistance with.
The first column are dates and times that reflect a ticket that opened. The second column reflects dates and times that a ticket closed.
I am needing to correlate all the dates of which every ticket opened and closed to its respective week of the month. So if I have 20 tickets that opened up between the days of 2/22/15 - 2/28/15(all these dates are in the same column fyi...), then I will be needing to somehow correlate these tickets in my spreadsheet to some form of data to be used in a line stack chart.
An exec has laid this on my lap. I don't look useless and I would like a little assistance as to how to perform such a task. Formulas in Excel...Vlookup....or using Pivot Tables....please assist!
convert date in excel to its respective week of the month
in conjunction with the date range example:
=INT((DAY(A1)-1)/7)+1
In column 3 use the =Weeknum(A1, 1) formula to get the week number of the date in column a. The second argument lets you determine what you want for the beginning of the week to be.
In column 4 do the same for column b. This will give you the week ticket opened/closed respectively. Add column 5 to be the difference in weeks which can be used in a pivot table to show the distribution of tickets and weeks to resolve, etc.
Reply back if you have further needs.
Firstly get the week num of the first day of the month -1
A1 = 01/02/2018
B1 = =WEEKNUM(A1)-1
Then calculate the individiual ticket week numbers and take the week number before the first week of the month away from the returned value. You may need to format the cells as numbers as some reason Excel thinks its a date
Open Week = =WEEKNUM(OpenDateCell)-$B$1
Close Week = =WEEKNUM(CloseDateCell)-$B$1
Representative Image:

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

Excel to specify the month to report the data

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.

Resources