Forum Discussion
Rhaly
5 years agoFrequent Visitor
[Dax] Count consecutive days and sequence
Hi, I'm kinda new in Power Pivot and i would ask some help 🙂 I have 2 columns in my table : Date and ID For each ID, i would like to add 2 columns in power pivot to: - count consecutive...
- 5 years ago
these code might work in calculated columns
Sequence= VAR vPrevTbl = FILTER ( Table1, Table1[ID] = EARLIER ( Table1[ID] ) && Table1[Date] <= EARLIER ( Table1[Date] ) ) VAR vPrevDate = ADDCOLUMNS ( vPrevTbl, "d", VAR vCurrentDate = Table1[Date] VAR vCurrentID = Table1[ID] VAR vPrevTbl = FILTER ( Table1, Table1[Date] <= vCurrentDate && Table1[ID] = vCurrentID ) RETURN MAXX ( FILTER ( vPrevTbl, VAR vCD = Table1[Date] VAR r = MAXX ( FILTER ( vPrevTbl, Table1[Date] < vCD ), Table1[Date] ) RETURN vcd - 1 <> r ), Table1[Date] ) ) RETURN COUNTROWS ( SUMMARIZE ( vprevdate, [d] ) )Count= VAR vCurrentDate = Table1[Date] VAR vCurrentID = Table1[ID] VAR vPrevTbl = FILTER ( Table1, Table1[Date] <= vCurrentDate && Table1[ID] = vCurrentID ) VAR vPrevDate = MAXX ( FILTER ( vPrevTbl, VAR vCD = Table1[Date] VAR r = MAXX ( FILTER ( vPrevTbl, Table1[Date] < vCD ), Table1[Date] ) RETURN vcd - 1 <> r ), Table1[Date] ) RETURN vCurrentDate - vPrevDate + 1
nleuck_101
1 year agoContinued Contributor
Hello,
Is there a way to exclude weekends? I've tried using WEEKDAYS not in 1 and 7 but it didn't work. Also my Sequence works just fine but not the Count. My count originally came over as a date. So I only get the count of 1 for each sequence. My count is the column on the right.