Forum Discussion
geminirand
2 years agoFrequent Visitor
Calculate percentage using previous row’s data with multiple filters
I'm stumped on how to handle this scenario. I have years of book sales data. "Sell Through" is how many people who bought book 1 in a series bought book 2, and so on. I have the numbers but not a...
- Anonymous2 years ago
Hi geminirand ,
Use this two DAXs to create measures:summed = VAR _Month = MONTH(MAX('Table'[Royalty_Date])) VAR _Book = MAX('Table'[Title]) VAR _Units = CALCULATE( SUM('Table'[Total_Units]), ALLEXCEPT('Table', 'Table'[Royalty_Date].[Year]), MONTH('Table'[Royalty_Date]) = _Month && 'Table'[Title] = _Book && ('Table'[Format_Abbr] = "Audio" || 'Table'[Format_Abbr] = "eBook" || 'Table'[Format_Abbr] = "HC" || 'Table'[Format_Abbr] = "PPB" ) ) RETURN _UnitsPrevious = VAR _Month = MONTH(MAX('Table'[Royalty_Date])) VAR _Book = MAX('Table'[Title]) VAR _Previous = CALCULATE( SUM('Table'[Total_Units]), ALLEXCEPT('Table', 'Table'[Royalty_Date].[Year]), MONTH('Table'[Royalty_Date]) = _Month && 'Table'[Book_Number] = MAX('Table'[Book_Number]) - 1 && ('Table'[Format_Abbr] = "Audio" || 'Table'[Format_Abbr] = "eBook" || 'Table'[Format_Abbr] = "HC" || 'Table'[Format_Abbr] = "PPB") ) RETURN _Previous
Especially here:
Then create two more measures to refer to the above two measures:all formats summed = SUMX(VALUES('Table'[Royalty_Date].[Month]), [summed])all formats percentage = VAR _a = SUMX(VALUES('Table'[Royalty_Date].[Month]), [all formats summed]) VAR _b = SUMX(VALUES('Table'[Royalty_Date].[Month]), [Previous]) RETURN IF( _b = BLANK(), 1, _a / _b )Then put these two measures above into the Matrix's Values:
And the final output is as below:
47+35+34=116
42+29+36=107
(42+29+36) / (47+35+34)=92.24%And when I change the slicer:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
geminirand
2 years agoFrequent Visitor
My measure is wrong in some way. It always shows 42407 for all results
geminirand
2 years agoFrequent Visitor
I think one reason for this is that I need to sum by the series slider. The report has sliders for series, year, and author name