Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
mmiljak
Regular Visitor

How to calculate sales same period last year using two dates order date and invoice date

Hi,

 I have been trying to solve this for sometime now and cannot get results when using two dates. I can for one date but not two.

I have tried adding 2 filter conditions in the calculate statement but to no evale.

 

I have the following tables;

dimOrderDate

dimInvDate

dimSales

 

in the dimSales table the full record of the sales is listed with sales amounts and both dates.

 

What I need is to be able to filter on both dates for last years sales amount. example of an output

 

Order dateinvoiced dateCurrent amountsamePeriodLastYear amount
01/01/201710/20/20173,3502,230

 

the same period last year dates are 

 

Order dateinvoiced dateCurrent amount
1/1/201610/20/20162,230

 

SAMEPERIODLASTYEAR AMOUNT =
CALCULATE(dimSales[Total sales]
,FILTER(ALL(dimOrderDatesDates)
,dimOrderDatesDates[YEAR]= MAX(dimOrderDates[YEAR])-1)
,FILTER(ALL(dimInvDates)
,dimInvDates[YEAR]=MAX(dimInvDates[YEAR])-1)
,SAMEPERIODLASTYEAR(dimInvDates[Inv_DATE])
,SAMEPERIODLASTYEAR(dimOrderDatesDates[Order_DATE]))

 

 

any help would be greatly appreciated

 

Mike

1 ACCEPTED SOLUTION

@mmiljak,

Yes. You can create DAX to bring invoice date and order date into dimsales table.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-yuezhe-msft
Employee
Employee

@mmiljak,

Assume that your dimSales table is as follows.
1.JPG

Create the following columns in your dimSales table.

Orderyear = YEAR(dimSales[Order date])
invoiceyear = YEAR(dimSales[invoiced date])
ordermonth = FORMAT(dimSales[Order date],"MM/DD")
invoicemonth = FORMAT(dimSales[invoiced date],"MM/DD")
samePeriodLastYear amount = CALCULATE(SUM(dimSales[sales]),FILTER(dimSales,dimSales[Orderyear]=EARLIER(dimSales[Orderyear])-1 &&dimSales[invoiceyear]=EARLIER(dimSales[invoiceyear])-1&&dimSales[ordermonth]=EARLIER(dimSales[ordermonth])&&dimSales[invoicemonth]=EARLIER(dimSales[invoicemonth])))

2.JPG

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much for getting back to me, Question do these new date fields need to be in the same table as sales?

I have 2 data tables for invoice and order dates that break down the dates to year, day, month, quater.....

 

The only one that I donot have is the month/day

 

Let me know.

 

Example;

 

dimInvDate

DIM_INVDATE_SEQINV_DATEYEARJVYEARJVMONTHTRFYEARTRFMONTHMONTHWEEKWEEKDAYQUARTERJVQUARTERSEASONJVSEASONDAY
29144905-JUN-10201020108201026237233SU156
29145031-MAY-10201020107201015222232SU151
29145101-JUN-10201020108201026223233SU152
29145202-JUN-10201020108201026224233SU153
29145309-JUN-10201020108201026234233SU160
29145410-JUN-10201020108201026235233SU161

@mmiljak,

Yes. You can create DAX to bring invoice date and order date into dimsales table.

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I have one more question. since we use sum in the calculate expression I cannot get a total when I use a table. If I sum the calculated colunm the total is incorrect. How can I add a total to the colunm in the table?

Hi,

 

share your dataset and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Here is my table the last colunm is calculated using a DAX formula. You can see that there is no total below only the Quantity has.

BI Table.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

If I sum the Last colunm the total is completly incorect you can see that it double sums some of the rows and the total is wrong.BI Table sum.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

So how do I get a total on this calculated colunm.

Here the formula

 

SAME_PERIOD_LAST_YEAR_RN = CALCULATE(sum(roomSales[QUANTITY]),FILTER(roomSales,roomSales[BOOK_YEAR]=EARLIER(roomSales[BOOK_YEAR])-1  && roomSales[STAY_YEAR]=EARLIER(roomSales[STAY_YEAR]) - 1 && roomSales[BOOK_MONTH]=EARLIER(roomSales[BOOK_MONTH]) && roomSales[STAY_MONTH]=EARLIER(roomSales[STAY_MONTH])))

 

Thank you for your help

Mike

 

 

Hi,

 

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you very much for all your help

Mike

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.