Forum Discussion
Most recent value based on two variables
If I understand, you're trying to get the latest date, and the max id associated with that date?
Using variables will make this easier to read. Additionally, SUMX is a row iterator, and can be quite slow on large data sets.
Try this:
Current_Valuation =
var _MaxDate = MAX(Stock_Value[New Date]) var _MaxID = CALCULATE(MAX(Stock_Value[uniqueno]),Stock_Value[New Date] = _MaxDate) RETURN CALCULATE(SUM(Stock_Value[newcost]) ,Stock_Value[New Date]=_MaxDate ,Stock_Value[uniqueno]=_MaxID )
Love hearing about Power BI tips, jobs and news?
I love to share about these - connect with me!
Stay up to date on
Read my blogs on
Remember to spread knowledge in the community when you can!
Thank you - this helps to select the right values. I have used the same fomula to calculate by quantity also:
Current_Quantity = var _MaxDate = MAX(Stock_Value[New Date]) var _MaxID = CALCULATE(MAX(Stock_Value[uniqueno]),Stock_Value[New Date] = _MaxDate) RETURN CALCULATE(SUM(Stock_Value[lev]) ,Stock_Value,Stock_Value[New Date]=_MaxDate,Stock_Value[uniqueno]=_MaxID )
It does create a couple of additional queries:
Firstly, the sum correctly - for example, total quantity states 50, rather than something 417,380
Secondly, they a filter the data by a product type rather than a stock code, this doesn't work. Is this were SUMX would work.
Can you help me?