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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
joseluis1969240
Frequent Visitor

Lost Customers, "dynamic measures"

Good morning,
I'm trying to create two 'dynamic' measures in DAX that provide me with the number of lost customers and the amount of sales those customers had. In my case, lost customers are the ones who haven't had any sales in either the current fiscal year or the two previous fiscal years. The measure I'm using to calculate the sales of lost customers is as follows:

joseluis1969240_0-1703222739650.png

If I use this measure without applying any date filter (fiscal year), the measure works fine. However, if I apply a filter by fiscal year in the pivot table, the data appears blank. What I want to achieve is for the measure to be dynamic, meaning if I select fiscal year 2024 in the pivot table, the result should be the lost customers in fiscal year 2024. If I select fiscal year 2023, the results should be the lost customers in fiscal year 2023...
Can you please help me?
Thank you very much in advance,
Kind Regards,

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @joseluis1969240 ,

I have created a simple sample, please refer to it to see if it helps you.

value_2 = var _1=SELECTEDVALUE('fiscal year'[year])
var _2yearsbefore=_1-3
return
IF(_1=SELECTEDVALUE('Table'[year]),MAX('Table'[sales amount]),BLANK())
value_3= var _1=SELECTEDVALUE('fiscal year'[year])
var _2yearsbefore=_1-3
var _3=IF(_1=SELECTEDVALUE('Table'[year]),MAX('Table'[customer]),BLANK())
var _4=
IF(_2yearsbefore=SELECTEDVALUE('Table'[year]),CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[year]=_2yearsbefore&&'Table'[customer]=SELECTEDVALUE('Table'[customer]))),BLANK()
)
return _3
Measure 4 = MAXX(FILTER(ALL('Table'),'Table'[customer]=SELECTEDVALUE('Table'[customer])),[value_3])
Measure 5 = var _1=SELECTEDVALUE('fiscal year'[year])
var _2yearsbefore=_1-3
var _4=
IF(_2yearsbefore=SELECTEDVALUE('Table'[year])&&[Measure 4]=BLANK(),CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[year]=_2yearsbefore&&'Table'[customer]=SELECTEDVALUE('Table'[customer]))),BLANK()
)
return _4

vrongtiepmsft_0-1703470486776.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

6 REPLIES 6
Anonymous
Not applicable

Hi @joseluis1969240 ,

I have created a simple sample, please refer to it to see if it helps you.

value_2 = var _1=SELECTEDVALUE('fiscal year'[year])
var _2yearsbefore=_1-3
return
IF(_1=SELECTEDVALUE('Table'[year]),MAX('Table'[sales amount]),BLANK())
value_3= var _1=SELECTEDVALUE('fiscal year'[year])
var _2yearsbefore=_1-3
var _3=IF(_1=SELECTEDVALUE('Table'[year]),MAX('Table'[customer]),BLANK())
var _4=
IF(_2yearsbefore=SELECTEDVALUE('Table'[year]),CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[year]=_2yearsbefore&&'Table'[customer]=SELECTEDVALUE('Table'[customer]))),BLANK()
)
return _3
Measure 4 = MAXX(FILTER(ALL('Table'),'Table'[customer]=SELECTEDVALUE('Table'[customer])),[value_3])
Measure 5 = var _1=SELECTEDVALUE('fiscal year'[year])
var _2yearsbefore=_1-3
var _4=
IF(_2yearsbefore=SELECTEDVALUE('Table'[year])&&[Measure 4]=BLANK(),CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[year]=_2yearsbefore&&'Table'[customer]=SELECTEDVALUE('Table'[customer]))),BLANK()
)
return _4

vrongtiepmsft_0-1703470486776.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

Good morning:
First of all, thank you for your response. I cannot test the solution because I am a Power Pivot user, and in Power Pivot, the SELECTEDVALUE function does not exist. Could you please tell me how I could adapt the DAX code to work with a different function than SELECTEDVALUE?
Thank you in advance

Dangar332
Super User
Super User

Hi, @joseluis1969240 

 

Sales loss customer=
 Var yearmax= selectedvalue (calendario [fiscal_year])
 Var result= sumx(
        All(ventas[customer Account]),
   Var sales3yrs = Calculate ( [sales], calendario [fiscal_year]<= yearmax,
        calendario [fiscal_year]>= yearmax-2)
  Var salesbefore3year = 
      Calculate ([sales], calendario [fiscal_year]< yearmax-2)
Return
If(isblank(sales3yrs), salesbefore3year, sales3yrs)
)
 Return 
Result 

Good morning:
Firstly, thank you for your response. I can't use the measurement you mentioned because the SELECTEDVALUE function doesn't exist in POWER PIVOT. Is it possible to modify the measurement using another function?
Thanks again

Hi, @joseluis1969240 

 

Try to replace selectedvalue with below

Var yearmax= max (calendario [fiscal_year])

Buenos días,
Gracias de nuevo por su respuesta. La solución que propones no funciona. A continuación, te mostraré los resultados proporcionados por la solución y cuáles son los resultados deseados:

joseluis1969240_0-1703322623525.png

Te agradecería mucho que siguieras ayudándome.
Gracias de antemano,

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.