If you want to get the last price paid for each part you have to type:
but for a part:
If(producto = 'A', Max(importe))
producto is the column name that contains part name you want to filter.
Note: in max function you have to include the column name that contains the price paid, not the poli_line_item_code.
I hope i have help you.
You have not explained how you are using this expression, but I assume its in a table or chart. The max() function will calculate the max of that value filtered by the dimension values on each row. Aggr() is incorrect in this context.
The easiest way to do this is with FirstortedValue:
FirstSortedValue(UOM_UNIT_PRICE_USD, -RECEIPT_DATE) is giving result for all the cases but not working when we have multiple records at the last receipt date, it is showing '-' for uom_unit_price_usd, i mean the last price paid. Is there a way if there are more than one records on max date then select max or avg of the price.
FirstSortedValue() won't work if you have two values same, try like this
=Only(aggr(if(max(TOTAL <PO_LINE_ITEM_CODE> RECEIPT_DATE))=RECEIPT_DATE, UOM_UNIT_PRICE_USD), PO_LINE_ITEM_CODE, RECEIPT_DATE))
Hope this helps you.
If not works then attach sample file.
If you want to handle this in script then try like below
Date(Max(RECEIPT_DATE) AS RECEIPT_DATE,
1 AS Flag
Group By PO_LINE_ITEM_CODE;