Forum Discussion
SUM with Filter based on a calculation
- 7 years ago
Hi Anonymous ,
Depending on what you need,
The formula I gave, I'm using it in a measure, but if you use it in a calculated column it won't work.
If you really need a calculated column, the first create a measure using the formula I gave.
Then create a calculated column where the column is equal to the measure.
MeaSalesbyNR = CALCULATE(SUM('Table'[SALES]),FILTER(ALL('Table'), 'Table'[NR] = MAX('Table'[NR]) +1))colSalesbyNR = [MeaSalesbyNR]
Hi Anonymous ,
Depending on what you need,
The formula I gave, I'm using it in a measure, but if you use it in a calculated column it won't work.
If you really need a calculated column, the first create a measure using the formula I gave.
Then create a calculated column where the column is equal to the measure.
MeaSalesbyNR = CALCULATE(SUM('Table'[SALES]),FILTER(ALL('Table'), 'Table'[NR] = MAX('Table'[NR]) +1))colSalesbyNR = [MeaSalesbyNR]
Thanks so much - sorry not to clarify that I needed a column!
What I also came up with is this solution for a column:
SalesByNr =
var CurrentNr = Tabelle1[nr]
return
CALCULATE(SUM(Tabelle1[sales]);FILTER(ALL('Tabelle1'); Tabelle1[nr] = CurrentNr +1))This gives me the same result.
In your opinion: are there any drawbacks to this solution?
Thanks
Chris
- Shawn_Fitz7 years agoFrequent Visitor
I think the formula you found is even better, since its processing time will be faster than the method I provided.