Situation:
I have a column (refund) that takes the MAX value for each day so that I don't duplicate the refunds.
refund =
var calcul =
CALCULATE(
SUM(Query1[amount]),
USERELATIONSHIP(Query1[created_at], DateTable[Date]),
Query1[kind] = "refund",
Query1[status] = "success"
)
This works for each day but the total is the max of that column
Objective:
I need this measure to calculate the net sales. I have the gross sales measure already but my refund formula doesn't work when aggregated.
What i tried (thanks to Alexis Olson):
refund =
var calcul =
CALCULATE(
SUM(Query1[amount]),
USERELATIONSHIP(Query1[created_at], DateTable[Date]),
Query1[kind] = "refund",
Query1[status] = "success"
)
return
SUMX(DISTINCT(Query1[orderId]), calcul)
However the output is unexpected. It basically takes each value and multiplies it by the distinct count of order ids on that day (refund or not).
So i tried dividing it by the distinct count of order id but the same problem with the total row taking the max value occurs.
Here's the output i get using the provided solution below:
Relationships:
Query1[created_at] DateTable[Date] (inactive)
Query1[orderDate] DateTable[Date] (active)
My returns measure:
Returns =
CALCULATE(
MAX(Query1[amount]),
USERELATIONSHIP(Query1[created_at], DateTable[Date]),
Query1[kind] = "refund",
Query1[status] = "success"
)
Returns
measure look like? Also, isDay
a table column (if so, what table)? – Alexis Olson