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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Last purchase value

Hello tod@s, I have the following scenario and problem, with the following two measures:

Measure Last Purchase Date:

Fecha_Ultima_Compra = LASTNONBLANK(Calendar[Date],[Valor_Precio_Unit_Final])
Measure Amount Last Purchase:
Monto_Ultima_Venta 2 = LASTNONBLANKVALUE(Calendar[Date],[Valor_Precio_Unit_Final])

With these two measures I am looking to obtain the last purchase value of any item, for this I am also using two segmenters one to filter by month and another to filter some particular item.

My problem is the following, when filter by month and by item, the table shows you the last value and date of purchase, according to the filtered month, however, if I ask for all the months, the table only shows the last value and date of purchase of the year of that filtered item, what I want is that in the table it shows you the last values and date of purchase of each month.

PS: the month of July still has no purchase of the selected item, maybe in other items yes.

I appreciate the help.

tabla_costeo.JPG

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

@Syndicate_Admin , I hope you are well,

I'm sorry it doesn't work for me, given the following:

  • I use a table called Calendar: "Calendar = CALENDAR(MIN(Compras_Detallada[f_fecha]), MAX(Compras_Detallada[f_fecha]))".
  • I have a relationship between two Tables: Compras_Detallada [f_fecha] & Calendar [Date].
  • To segment or filter dates I use the calendar table, in this case the segmenter is Calendar [Month].

I attach my . Pbix

Anonymous
Not applicable

Hi  @Syndicate_Admin ,

I created some data:

vyangliumsft_0-1690186365238.png

 

Here are the steps you can follow:

1. Create calculated table.

Calendar =
DISTINCT('Table'[Month])

vyangliumsft_1-1690186365240.png

2. Create measure.

Flag =
var _selectmonth=SELECTCOLUMNS('Calendar',"month",[Month])
var _selectitem=SELECTEDVALUE('Table'[item])
var _maxdate=MAXX(
    FILTER(ALL('Table'),
    'Table'[Month] in _selectmonth && 'Table'[item]=_selectitem&&'Table'[Month]=MAX('Table'[Month])),[Date])
return
IF(
    MAX('Table'[Date]) =_maxdate,1,0)

 3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_2-1690186409576.png

4. Result:

vyangliumsft_3-1690186409578.png

 

 

Best Regards,

Liu Yang

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

rubayatyasmin
Super User
Super User

Hi, @Syndicate_Admin 

 

you need to modify the measures to consider both the item and the month context when calculating the last purchase date and amount.

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.