cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Pavlhs90
New Member

% change over time by product ID

Hello All,

 

I am trying to write a measure that will calculate percentage change of price overtime (from oldest to most recent date) by product ID. The measure should be comparing the price of a product on a date with the price of the same product on the exact previous date.

 

The outcome should be the following:

 

Product_IDDate Price % change
12020-01-01 10  
12020-04-01 15 50%
12022-08-15 30 100%
22015-01-01 50  
22019-06-01 25 -50%
32018-01-01 50  
32020-06-01 15 -70%
32022-08-15 30 100%
32023-08-15 90 200%
32024-09-01 110 22%

So far I have the following:


Percent Change =
var _pre=MAXX(FILTER(ALL('TABLE'),[Start Date]= CALCULATE(MAX([Start Date]),FILTER(ALL('TABLE'),[Start Date]<MAX('TABLE'[Start Date])))),[Price])
return DIVIDE(MAX([Price])- _pre,_pre)

 

This only seems to work when I filter the dataset on 1 product at a time.

Any ideas?

 

Regards
Pav

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

This is the standard "Penultimate"  pattern.  Just a couple of steps, no need to bring out the big guns ( "ALL"  is very loud). Note this will only work if the data aggregated to the product and date levels. (well, technically the product level don't matter much).  Note that my  % change formula is slightly different from yours.  There are some weird and wonderful things happening when the adjacent data values have different signs...

 

lbendlin_0-1695949693125.png

 

View solution in original post

2 REPLIES 2
Pavlhs90
New Member

@lbendlin  Thank you!!

lbendlin
Super User
Super User

This is the standard "Penultimate"  pattern.  Just a couple of steps, no need to bring out the big guns ( "ALL"  is very loud). Note this will only work if the data aggregated to the product and date levels. (well, technically the product level don't matter much).  Note that my  % change formula is slightly different from yours.  There are some weird and wonderful things happening when the adjacent data values have different signs...

 

lbendlin_0-1695949693125.png

 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors