Forum Discussion
Column (or measure) based on slicer value
Hello community.
I need assistance.
I have two tables: Sales and Prices.
The task is to calculate sales amount : amount = Sales.quantity * Prices.latest Price for that SKU, which depends on price type, selected in slicer.
I did first part (found latest price by sku) by creating such column:
And that is ok. But I got stuck with the second part of the task (can't consider selected price type).
I've created measure:
Thank you.
- Anonymous6 years ago
Anonymous Thanks for the explaining. so date in price table should be less then sales date.
Measure = VAR _pricetype = SELECTEDVALUE(Prices[PriceType]) VAR _date = MAX(Sales[Date]) VAR _sku = MAX(Sales[SKU]) VAR _latestDate = CALCULATE(MAX(Prices[PriceDate]),Prices[SKU]=_sku,Prices[PriceType]=_pricetype,Prices[PriceDate]<=_date) VAR _latestPrice = CALCULATE(MAX(Prices[Price]),Prices[SKU]=_sku,Prices[PriceDate]=_latestDate,Prices[PriceType]=_pricetype) RETURN SUMX(Sales,Sales[Qty]*_latestPrice)
6 Replies
- AnonymousNot applicable
Anonymous Please try below
Measure = VAR _pricetype = SELECTEDVALUE(Prices[PriceType]) VAR _sku = MAX(Sales[SKU]) VAR _latestDate = CALCULATE(MAX(Prices[PriceDate]),Prices[SKU]=_sku,Prices[PriceType]=_pricetype) VAR _latestPrice = CALCULATE(MAX(Prices[Price]),Prices[SKU]=_sku,Prices[PriceDate]=_latestDate,Prices[PriceType]=_pricetype) RETURN SUMX(Sales,Sales[Qty]*_latestPrice)measure
- AnonymousNot applicable
Anonymous thank you for reply.
It is ok with price type, but now it is wrong with first part of the task.
This measure takes latest price of all prices of that type.
Take a look at example below, amount for sale 15.10.2019 is incorrect:- AnonymousNot applicable
Anonymous
Sorry I didn't get you what's wrong here
for 15.10.2019 Quantity is 15 and sku is 11 so as per logic for sku 11 and price type A latest price is 333 hence total is15*333 = 4995
Please help me with expected result that you are looking for
Do you mean price date should be less then equal to date?