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
Rhaly
5 years agoFrequent Visitor
Hey,
Sorry to bother you again. The 2 measure works very well.
I need now to add a parameter --> On the count measure, i need to not count when it's a sunday and add 1 if both saturday and monday have occurence.
I understood like 80% of the count measure but i can see where i can add this condition.
Any help will be gratefull 🙂
It would be like this in excel :