Forum Discussion
DAX Calculation
- 8 months ago
Hi KristinaLeo,
I hope you are doing well ☺️❤️
Try this it should work:
Tier Weighted Stable Product Contribution % = VAR SelectedPeriodDates = ALLSELECTED('Date'[Date]) VAR PeriodStart = MINX(SelectedPeriodDates, [Date]) VAR PeriodEnd = MAXX(SelectedPeriodDates, [Date]) -- Products active the entire selected period VAR StableProducts = FILTER( ALL(Products), Products[LaunchDate] <= PeriodStart && (ISBLANK(Products[DiscontinuedDate]) || Products[DiscontinuedDate] > PeriodEnd) ) -- Convert to single column table of ProductIDs for TREATAS VAR StableProductIDs = SELECTCOLUMNS(StableProducts, "ProductID", Products[ProductID]) -- Customers who signed up before period start VAR EstablishedCustomers = FILTER( ALL(Customers), Customers[SignupDate] < PeriodStart ) -- Convert to single column table of CustomerIDs for TREATAS VAR EstablishedCustomerIDs = SELECTCOLUMNS(EstablishedCustomers, "CustomerID", Customers[CustomerID]) -- Weighted revenue from transactions that match both lists VAR WeightedQualifiedRevenue = CALCULATE( SUMX( Sales, Sales[Revenue] * SWITCH( RELATED(Customers[Tier]), "A", 1.2, "B", 1.0, "C", 0.8, 1.0 ) ), -- Apply filters using TREATAS for reliable filtering TREATAS(StableProductIDs, Sales[ProductID]), TREATAS(EstablishedCustomerIDs, Sales[CustomerID]) ) -- Total revenue for the same date context (keep Date filters and remove other filters) VAR TotalPeriodRevenue = CALCULATE( SUM(Sales[Revenue]), ALL(Products), ALL(Customers), ALL(Sales[ProductID]), ALL(Sales[CustomerID]) -- Date filters are preserved automatically ) RETURN DIVIDE( WeightedQualifiedRevenue, TotalPeriodRevenue, BLANK() )if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.
KristinaLeo , you can try a measure like
Measure =
Var _min = minx(allselected('Date'), 'Date'[date])
Var _max = maxx(allselected('Date'), 'Date'[date])
var _product = Summarize( filter(Products, Products[DiscontinuedDate] <= _max), Products[ProductID])
var _customer = Summarize( filter(Customers, Customers[SignupDate] < _min), Customers[CustomerID])
Return
calculate([Your Measure], Filter(Products, Products[ProductID] in _product), filter(Customers,Customers[CustomerID] in _customer))
- KristinaLeo8 months agoNew Member
Thank you for your response, but this measure will not give correct results in all cases especially on larger datasets or for products that were discontinued during the selected period, Thanks again for your response