Forum Discussion
Consecutive Successes in a Time Frame
I have the strangest problem. I am trying to count the number of consecutive successes.
| Outcome | Consec | Outcome | Consec | |
| Success | 1 | Fail | 0 | |
| Success | 2 | Success | 1 | |
| Success | 3 | Fail | 0 | |
| Fail | 0 | Fail | 0 | |
| Success | 1 | Success | 1 |
Whenever it starts with a failure - it works fine. When it starts with a success, I am having erratic results until the first failure. After the first failure, it works great. But here are some examples of what I am experiencing:
Sometimes when it starts with a success, it works great
One time it should count 1, 2, 3 but it is returning 1,1, 2
Two times it should count 1, 2, 0 but it is returning 1, 1, 0
One time it should count 1, 2, 3, 4, 5, 6 but it is returning 1, 2, 2, 3, 3, 4
I have no idea what is going wrong. I have attached a sample file from which I have whittled down the columns in the tables. Here is the DAX that is going awry.
https://mwtn-my.sharepoint.com/:u:/g/personal/dkernen_mwtn_org/Eb5EH7AtrKRFiyajN7EqsIkBDBL9Z8SbIbt-o7YxB0_YcA?e=1Rdqn0
++++Addition++++
If I do not exclude any columns in Power Query, then I get a different problem, albeit at least consistent. In this scenario, again the ones that start with a failure work perfectly. If they start with a success, the count does not increment until the first failure. So I am getting
| Outcome | Consec | Rather than | Outcome | Consec |
| Success | 1 | Success | 1 | |
| Success | 1 | Success | 2 | |
| Success | 1 | Success | 3 |
Here is the one without removed columns
https://mwtn-my.sharepoint.com/:u:/g/personal/dkernen_mwtn_org/EX7yjZeTPA5DqzEDiZXQBVkBwW1-fevSBXEmiELhsXOvoA?e=UT3Y9J
Any thoughts? I am completely at a loss. Thank you.
dkernen What about this:
Recovery for Count = VAR __referralDT = [Referral_DT Measure] VAR __group = MAX('dimODisp'[ORecovered_N]) VAR __tmpTable1 = FILTER(ALLSELECTED('dimODisp'),[Referral_DT]<=__referralDT) VAR __tmpTable1a = ADDCOLUMNS(__tmpTable1,"__Index",COUNTROWS(FILTER(__tmpTable1,[Referral_DT]<=EARLIER([Referral_DT])))) VAR __tmpTable1b = FILTER(__tmpTable1a,[ORecovered_N] = __group) VAR __tmpTable2 = ADDCOLUMNS( __tmpTable1b, "__diff",[__Index] - MAXX(FILTER(__tmpTable1b,[__Index]<EARLIER([__Index])),[__Index])) VAR __max = MAXX(__tmpTable2,[__Index]) VAR __maxStart = MAXX(FILTER(__tmpTable2,[__diff]>1),[__Index]) VAR __tmpTable3 = FILTER(__tmpTable2,[__Index]>=__maxStart) RETURN SWITCH(TRUE(), __group = 0,0, ISBLANK(__max),1, __max=__maxStart,1, COUNTROWS(__tmpTable3) )The final solution for this was posted as a Quick Measure Gallery Entry, Bride of Cthulhu!
7 Replies
- Greg_DecklerCommunity Champion
dkernen This is Cthulhu: Cthulhu - Microsoft Power BI Community
- dkernenResolver II
Greg_Deckler
Greg - this is incredible. However, I am summing a field to make a running sum rather than using an index and I am still stuck. It is still incorrect before the first "failure."
I commented my DAX to match your heroic Cthulhu. Would you be willing to look at my specific example?
https://mwtn-my.sharepoint.com/:u:/g/personal/dkernen_mwtn_org/EX7yjZeTPA5DqzEDiZXQBVkBwW1-fevSBXEmiELhsXOvoA?e=47eTwH
I would really appreciate your expertise.- Greg_DecklerCommunity Champion
dkernen OK, what is the actual triggering event for when the counter should reset? I can't figure that out from looking at things. Is it when the Organ Outcome changes?
- Greg_DecklerCommunity Champion
The final solution for this was posted as a Quick Measure Gallery Entry, Bride of Cthulhu!