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
marcgro
Frequent Visitor

Calculate the maximum drop in my sales data

Hello guys, 

 

I'm new to dax, and while I'm reading my ressource book there is a problem that I would like to solve that would help me immensely.

 

I have sales data for every one of my customers monthly over 5 years(With a date hierarchy set up). I would like to be able to calculate my maximum drop in sales for every customer. The drop should not be only a year to year drop. i.e. it would be the maximum value of the difference in sales between two of my years, assuming the lower sales year comes after the higher sales year.

 

i.e:

 

for customer 1:

YearSales

2015

20
2016400
2017180
2018150
2019160

 

Return: 250 (is 400 - 150)

 

In the same way:

 

for customer 2:

YearSales

2015

300
201620
2017450
2018220
2019200

Return: 280 (300-20)

 

I hope you get the point.

One added layer of complexity is that since my sales data is monthly, it has to be aggregated to yearly before looking like the above tables.

 

Thanks in advance, all!

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @marcgro 

Create measures

sale_yearly = CALCULATE(SUM('Table'[sales]),FILTER(ALLSELECTED('Table'),'Table'[customer]=MAX('Table'[customer])),VALUES('date'[year]))

Measure = MINX(FILTER(ALLSELECTED('Table'),[year]>=MAX('Table'[year])),[sale_yearly])

Measure 2 = [sale_yearly]-[Measure]

Measure 3 = MAXX(ALLSELECTED('Table'),[Measure 2])

Capture6.JPGCapture7.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @marcgro 

Create measures

sale_yearly = CALCULATE(SUM('Table'[sales]),FILTER(ALLSELECTED('Table'),'Table'[customer]=MAX('Table'[customer])),VALUES('date'[year]))

Measure = MINX(FILTER(ALLSELECTED('Table'),[year]>=MAX('Table'[year])),[sale_yearly])

Measure 2 = [sale_yearly]-[Measure]

Measure 3 = MAXX(ALLSELECTED('Table'),[Measure 2])

Capture6.JPGCapture7.JPG

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

Assuming they are in the same table. You can have a year from the month.

 

Measure = 
var _a = SUMMARIZE('Table','Table'[customer],'Table'[Year],"_SUM",SUM('Table'[Sales]))
return
sumx(SUMMARIZE(_a,[customer],"_min",Minx(_a,[_sum]),"_max",Maxx(_a,[_sum])),[_max]-[_min])

 

Mark me @ for more info.

Appreciate your Kudos.

Thanks for your quick reply. 

 

I am not getting the results that I want, because I think your formula misses out on the point that the low value should come at a later date than the high value (as I showed in the examples above).

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.