cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
sloopools
Regular 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.
table.png

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

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 😞 

View solution in original post

sloopools
Regular 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

View solution in original post

3 REPLIES 3
sloopools
Regular 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

some_bih
Super User
Super User

Hi @sloopools 

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

Hope this help, kudos appreciated.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






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 😞 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors