Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sloopools
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.
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
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

View solution in original post

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

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.