cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Calculated column based on subset of data filtered by values on each row

Hello!
I have a table with some ORDER movements during a certain period (DATE).
Consider a ChainValue where the main company ships its products to it's retailers/Customers (DEST_CUSTOMERS) and then the retailers further sell to their final customers.
Each transaction represents has it's own costs (TRANSPORT, DOCS and INSURANCE) for a certain WEIGHT.

GOAL: Calculate the sum of costs for each ORDER that a RETAILER sends to a final CUSTOMER, considering the averaged costs that the SOURCEproducer had by sending products to his location in the past few X-days.
In other word, for each row I would have:
Total_Costs = sum(TRANSPORT) + sum(DOCS) + sum(INSURANCE) + AveragedCostsFromSource
(In practice, this AveragedCostsFromSource) would be an weighted average of its costs, depending on weight beeing transported)

The Problem: I cretated a Calculated Measure that works fine, but because of performance issues and memory limitation, I am unable to see more that some thousand lines calculation and summarized in a visualization table, Howevere I have 6 millions rows in this dataset so I thought a calculated column would solve my problem.

Need therefore help creating a correspodent Calculated Column from my Measure AveragedCostsFromSource. I tryed several approaches but didn't get anything to work (it shows me blanks or it's not accepting some of the filters). Maybe this is not the best approach either, so feel free to comment the best approach.
Thanks.

Measure:
AveragedCostsFromSource =

var _selectedCustomer =
SELECTEDVALUE
(OrderSales_Data[Warehouse_to_Customer_Mapping])
var _invoiceDate_from =
SELECTEDVALUE(OrderSales_Data[INVOICEDATE-7Days])  //I have this as a calculated column
var _invoiceDate_until =
SELECTEDVALUE(OrderSales_Data[INVOICEDATE])
var _VolumeWeight =
SELECTEDVALUE(OrderSales_Data[WEIGHT]) // for each row

var _calc =
sumx(OrderSales_Data,
calculate(
_VolumeWeight * (
( sum(OrderSales_Data[TRANSPORTS]) + sum(OrderSales_Data[TRANSPORTS]) + sum(OrderSales_Data[TRANSPORTS]) )
/ sum(OrderSales_Data[TRANSPORTS])
), // This ends the Weighted average calculation
REMOVEFILTERS(OrderSales_Data),
OrderSales_Data[Seler] = "SourceProducer",
OrderSales_Data[CUSTOMERGROUP] = "40",
FILTER(OrderSales_Data, OrderSales_Data[DEST_CUSTOMER] = _selectedCustomer),
OrderSales_Data[INVOICEDATE] > _invoiceDate_from,
OrderSales_Data[INVOICEDATE] <= _invoiceDate_until
)
)
return
_calc

2 ACCEPTED SOLUTIONS
Frequent Visitor

Thanks for noticing. Forgot to put in that line when I copy&past it from my original file.
But that was not the solution for problem 😞

Frequent Visitor

Solved the problem myself. Simple actually!
As a calculated column one has to use the rowvalue and not the SELECTEDVALUE as used on my measure. Thanks anyway guys

3 REPLIES 3
Frequent Visitor

Solved the problem myself. Simple actually!
As a calculated column one has to use the rowvalue and not the SELECTEDVALUE as used on my measure. Thanks anyway guys

Super User

in measure you have part "_selectedCustomer" but no VAR for this part.

Hope this help, kudos appreciated.

Proud to be a Super User!

Frequent Visitor

Thanks for noticing. Forgot to put in that line when I copy&past it from my original file.
But that was not the solution for problem 😞