Compare if Product Current Row Matches the Same Product Previous Month

nikkollai

New Member
Joined
Sep 10, 2014
Messages
49
Hello,

I would really appreciate some help on this one. Let's say we have no dims and facts just a simple extended product table below.

How would you compare if Unit Price matches or not with the price of the same product sold the previous month?



Thank you


ProductIdDateKeyDateQttySold UnitPrice
14344201637001/27/2016134 6.00
16239201638001/28/2016389 9.00
16239201639001/29/20162334 10.00
15233201640001/30/20161983 9.00
12657201641001/31/20162872 9.00
13972201621002/1/20161897 7.00
18123201622002/2/20163132 9.00
15795201623002/3/20163343 5.00
18643201624002/4/20163354 9.00
13294201625002/5/20161204 9.00
14806201626002/6/2016819 7.00
13997201627002/7/20162484 9.00
11787201628002/8/20162145 10.00
17145201629002/9/20162341 4.00
12657201630002/10/20162139 6.00
16786201631002/11/20162570 10.00
12657201632002/12/20163123 6.00
16239201633002/13/20161520 5.00
12657201634002/14/20161905 4.00
16325201635002/15/20161956 4.00
17550201636002/16/20161628 7.00

<tbody>
</tbody>
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi,
As there is the possibility of multiple products with different prices sold in the previous month you can check the price from this sale with the prices from previous months by

  1. sum the price of the product if the product is similar to sold products in the previous month
  2. count the number of transactions if the product is similar to previous sold products in the previous month
  3. divide 1 and 2
  4. you become the average price per product in the previous month.
  5. compare that to the price of this month's sale;
  6. if they are similar; prices are the same; if they differ than you've used different prices.

This is one way of doing it:

Excel 2016 (Windows) 64 bit
ABCDEF
1ProductIdDateKeyDateQttySoldUnitPricePrev Mth Price
2143442016370027-1-20161346 
3162392016380028-1-20163895
4162392016390029-1-201623345
5152332016400030-1-201619839
6126572016410031-1-201628729
713972201621001-2-201618977
818123201622002-2-201631329
915795201623003-2-201633435
1018643201624004-2-201633549
1113294201625005-2-201612049
1214806201626006-2-20168197
1313997201627007-2-201624849
1411787201628008-2-2016214510
1517145201629009-2-201623414
16126572016300010-2-201621396FALSE
17167862016310011-2-2016257010
18126572016320012-2-201631236FALSE
19162392016330013-2-201615205TRUE
20126572016340014-2-201619054FALSE
21163252016350015-2-201619564
22175502016360016-2-201616287
Sheet1
Cell Formulas
RangeFormula
F2=IFERROR(SUMPRODUCT((A2=$A$2:A2)*(MONTH(C2)-1=MONTH($C$2:C2)),($E$2:E2))/SUMPRODUCT((A2=$A$2:A2)*(MONTH(C2)-1=MONTH($C$2:C2)))=E2,"")




NB: i modified your data to make sure there was at least one row which evaluates to true.
 
Last edited:
Upvote 0
I assume you are looking for a power pivot solution, not an excel solution. I suggest creating a calendar table with a month ID column. Read about why here Power Pivot Calendar Tables - Excelerator BI

then you can write something like this.

Avg price previous month = calculate(average(data[unit price]), filter(all(calendar),calendar[monthID]=max(calendar[monthID])))
 
Upvote 0
jorismoerings

You presented a very detailed answer thank you very much. Even though I was hoping for a DAX code it is great to see an excel solution. Serves a reminder once again that excel is indeed a very powerful and flexible tool.

N -


Hi,
As there is the possibility of multiple products with different prices sold in the previous month you can check the price from this sale with the prices from previous months by

  1. sum the price of the product if the product is similar to sold products in the previous month
  2. count the number of transactions if the product is similar to previous sold products in the previous month
  3. divide 1 and 2
  4. you become the average price per product in the previous month.
  5. compare that to the price of this month's sale;
  6. if they are similar; prices are the same; if they differ than you've used different prices.

This is one way of doing it:
Excel 2016 (Windows) 64 bit
ABCDEF
1ProductIdDateKeyDateQttySoldUnitPricePrev Mth Price
2143442016370027-1-20161346
3162392016380028-1-20163895
4162392016390029-1-201623345
5152332016400030-1-201619839
6126572016410031-1-201628729
713972201621001-2-201618977
818123201622002-2-201631329
915795201623003-2-201633435
1018643201624004-2-201633549
1113294201625005-2-201612049
1214806201626006-2-20168197
1313997201627007-2-201624849
1411787201628008-2-2016214510
1517145201629009-2-201623414
16126572016300010-2-201621396FALSE
17167862016310011-2-2016257010
18126572016320012-2-201631236FALSE
19162392016330013-2-201615205TRUE
20126572016340014-2-201619054FALSE
21163252016350015-2-201619564
22175502016360016-2-201616287

<colgroup><col style="width: 25pxpx"><col><col><col><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
F2=IFERROR(SUMPRODUCT((A2=$A$2:A2)*(MONTH(C2)-1=MONTH($C$2:C2)),($E$2:E2))/SUMPRODUCT((A2=$A$2:A2)*(MONTH(C2)-1=MONTH($C$2:C2)))=E2,"")

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>





NB: i modified your data to make sure there was at least one row which evaluates to true.
 
Upvote 0
Thank you Matt,

I am not sure If I am on the right track here but I feel like the DAX should look something like this. The issue is to figure out that comparing expression below marked in red.


=CALCULATE(
"EXPRESSION COMPARING CURRENT MONTH UNIT PRICE WITH PREVISOU HERE????",
FILTER(
ALL(DataTable),
DataTable[ProductID] = EARLIER(DataTable[ProductID])
)
)




N-



I assume you are looking for a power pivot solution, not an excel solution. I suggest creating a calendar table with a month ID column. Read about why here Power Pivot Calendar Tables - Excelerator BI

then you can write something like this.

Avg price previous month = calculate(average(data[unit price]), filter(all(calendar),calendar[monthID]=max(calendar[monthID])))
 
Upvote 0
Thank you Matt,

I am not sure If I am on the right track here but I feel like the DAX should look something like this. The issue is to figure out that comparing expression below marked in red.

=CALCULATE(
"EXPRESSION COMPARING CURRENT MONTH UNIT PRICE WITH PREVISOU HERE????",
FILTER(
ALL(DataTable),
DataTable[ProductID] = EARLIER(DataTable[ProductID])
 )
)

Sorry for the slow reply. No this is not really the approach. The trick is to break the problem into pieces.

  1. Get the value for this period
  2. Get the value for the previous period
  3. compare 1 to 2 to get the comparison you need.

So the secret sauce is in the FILTER statement. This is a time shifting formula. It goes back in time to fetch the same expression but at a previous point it time (it is a time machine). Does that make sense?
 
Upvote 0

Forum statistics

Threads
1,214,987
Messages
6,122,618
Members
449,092
Latest member
amyap

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top