Forum Discussion
dax count how many consecutive days
- 8 years ago
Try this MEASURE
Measure = VAR starting = CALCULATE ( MAX ( TableName[Date] ), FILTER ( ALLEXCEPT ( TableName, TableName[MachineNr] ), TableName[Date] < SELECTEDVALUE ( TableName[Date] ) && TableName[ProjectNr] <> SELECTEDVALUE ( TableName[ProjectNr] ) ) ) VAR Seriesstart = IF ( ISBLANK ( starting ), CALCULATE ( MIN ( TableName[Date] ), FILTER ( ALLEXCEPT ( TableName, TableName[MachineNr] ), TableName[Date] < SELECTEDVALUE ( TableName[Date] ) ) ) - 1, starting ) RETURN DATEDIFF ( Seriesstart, SELECTEDVALUE ( TableName[Date] ), DAY )
Try this MEASURE
Measure =
VAR starting =
CALCULATE (
MAX ( TableName[Date] ),
FILTER (
ALLEXCEPT ( TableName, TableName[MachineNr] ),
TableName[Date] < SELECTEDVALUE ( TableName[Date] )
&& TableName[ProjectNr] <> SELECTEDVALUE ( TableName[ProjectNr] )
)
)
VAR Seriesstart =
IF (
ISBLANK ( starting ),
CALCULATE (
MIN ( TableName[Date] ),
FILTER (
ALLEXCEPT ( TableName, TableName[MachineNr] ),
TableName[Date] < SELECTEDVALUE ( TableName[Date] )
)
)
- 1,
starting
)
RETURN
DATEDIFF ( Seriesstart, SELECTEDVALUE ( TableName[Date] ), DAY )- Zubair_Muhammad8 years ago
Community Champion
- ABC113 years ago
Resolver I
Hello Zubair
I need help- I would like to "do No of consecutive day worked by employee"
I try to follow this code- I am getting error
"A single value for column 'WORKDATE' in table 'New LEM Facts' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."
No_Of_Days = VAR starting = CALCULATE( Max('New LEM Facts'[WORKDATE]), FILTER( ALLEXCEPT('New LEM Facts', 'New LEM Facts'[CONTRACT_NO]), 'New LEM Facts'[WORKDATE]<SELECTEDVALUE( 'New LEM Facts'[WORKDATE]) ) ) VAR Seriesstart= if( ISBLANK(starting), CALCULATE( MIN('New LEM Facts'[WORKDATE]), FILTER( ALLEXCEPT('New LEM Facts','New LEM Facts'[WORKDATE]), 'New LEM Facts'[WORKDATE]<SELECTEDVALUE('New LEM Facts'[WORKDATE]) ) ) -1, starting ) Return DATEDIFF(Seriesstart,SELECTEDVALUE('New LEM Facts'[WORKDATE]),DAY)Thanks
- Anonymous3 years agoNot applicable
I have the exact same problem - and when trying to change SELECTEDVALUE with IF ( HASONEVALUE ( T[c] ), VALUES ( T[c] ), BLANK() ) it doesn't work....
- ben_w8 years agoFrequent Visitor
This is working exactly as it should! Many thanks.
I've only had to change the code a little to work with my dimensions (which i for simplicity reasons didn't mention), and changed the "SELECTEDVALUE" function to "IF ( HASONEVALUE ( T[c] ), VALUES ( T[c] ), BLANK() )" to be able to use it in DAX for SSAS Tabular 2016.