Forum Discussion
KristinaLeo
8 months agoNew Member
DAX Calculation
Hi Everyone, I require a measure that calculates for each customer tier the percentage of total revenue contributed by only products that were active for the entire duration of the current time peri...
- 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.
Ahmed-Elfeel
8 months agoSuper User
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
8 months agoNew Member
Thanks Ahmed for this measure it is a bit longer, but this version is the best for production because its maintainable and works correctly with dynamic date selections; Exactly what I was looking for.
Additional if I place this measure in a Matrix visual with Customers[Tier] on rows, will the Total row automatically sum to 100% across all tiers or do I need to adjust the measure for proper total calculation?