Forum Discussion
Sum all values per row until limit is reached with multiple criteria
what is you code for the column yearFrac_Remainder?
- sturlaws7 years ago
Resident Rockstar
It does not really make any sense to me, this last operation of yours, but here is how you need to do it.
In Power BI there is no way of referencing a cell directly like you would in Excel. You use similar approach as was used in [Number of days]-column:number of days NEW = VAR LastEndDate = CALCULATE ( MAX ( data[Contract End Date] ); FILTER ( ALL ( data ); data[Account ID] = EARLIER ( data[Account ID] ) && data[Product Category] = EARLIER ( data[Product Category] ) ) ) VAR _contract = data[Contract Number] VAR _product = data[Product Category] RETURN IF ( data[Contract End Date] < LastEndDate; [Number of days] - CALCULATE ( MIN ( data[YearFrac_remainder] ); FILTER ( ALL ( data ); data[Contract End Date] = LastEndDate && data[Contract Number] = _contract && data[Product Category] = _product ) ); [Number of days] ) - Anonymous7 years agoNot applicable
sturlaws - Thank you so much for all your help! I've put a lot of time into making many improvements and your code is pushing me in the right direction. I am so close and just have one last hurdle that I need to solve with this report that I wanted to see if I could get your help with.
Currently, my calculations are pulling the last 12 months of revenue starting at the max contract end date filtered by account ID and product category but I also need to make the max date filter relative to specific ID# searches.
Here's an example to explain:
Account ID Opportunity ID # Products Start Date End Date Term
1234 DR1234 Analytics 1/1/2020 5/31/2020 5 months
1234 DR2345 Analytics 12/1/2018 11/31/2019 12 months
1234 DR4321 Analytics 4/1/2018 11/31/2018 8 months
Currently, the dashboard will look for the max end date of 5/31/2020 and take 5 months of revenue from the top line and 7 months of revenue from the 2nd line to get a total of 12 months. This is good and this calculation should be the default but let's say I do a search for the first line above by filtering on the opportunity ID# DR1234. If I did this then I'd need the first line to be ignored in the calculation, have the max end date be identified as 11/31/2019, and in this example, I'd be able to pull all of the past 12 months of revenue that I am looking for just from the second line alone.
Another way to say this would be that I need to do the same 12-month calculation but it needs to act relative to a filter/search and begin counting the prior 12 months of revenue, starting on the latest end date of the opportunity ID# prior to the earliest start date of the ID# that I am searching for.
One last piece to this problem:
The above example is easy since if I searched for DR1234 then the lines with ID# DR1234 would be ignored and the 12-month calculation would start 11/31/2019 and would go back until 12/1/2018. However, one of these lines can only be included in this calculation if the latest end date of the prior ID# is <= 6 months from the earliest start date of the new ID# that is being searched for. So, for example, if I searched for DR1234 and the next soonest end date was 3/1/2019 then the calculation should return $0 for revenue because there were no prior ID#s within the past 6 months. But if the next soonest end date, from DR1234's start date, was 7/1/2019 then that line should be included in the calculation and the 12-month look-back period should start on 7/1/2019 and go back until 6/31/2018.
I know this is a lot of information and it is very tricky but please let me know if you need more clarification on this final problem that I am trying to solve and again thank you for all your help!
- Anonymous7 years agoNot applicable