Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Total difference between current and previous date

Hi All,   Could you please help writing DAX code for below query:   I have a dataset with lots of columns but only below columns are more relavent to this query: SnapshotDate CreatedDate Ta...
  • Anonymous's avatar
    Anonymous
    6 years ago

    HI Anonymous ,

    You can try to use the following measure formulas if they suitable for your requirements:

    Total closed = 
    CALCULATE (
        COUNT ( T1[TaskID] ),
        FILTER ( ALLSELECTED ( T1 ), [SnapshotDate] <= MAX ( T1[SnapshotDate] ) )
    )
    
    Previous Closed = 
    VAR currDate =
        MAX ( T1[SnapshotDate] )
    VAR prevDate =
        CALCULATE (
            MAX ( T1[SnapshotDate] ),
            FILTER ( ALLSELECTED ( T1 ), [SnapshotDate] < currDate )
        )
    RETURN
        IF (
            prevDate <> BLANK (),
            CALCULATE (
                COUNT ( T1[TaskID] ),
                FILTER (
                    ALLSELECTED ( T1 ),
                    [SnapshotDate] <= currDate
                        && [SnapshotDate] > prevDate
                )
            )
        )
    
    Last Closed =
    VAR currDate =
        MAX ( T1[SnapshotDate] )
    VAR _lastDate =
        CALCULATE ( MAX ( T1[SnapshotDate] ), ALLSELECTED ( T1 ) )
    RETURN
        IF (
            currDate = _lastDate,
            CALCULATE ( COUNT ( T1[TaskID] ), VALUES ( T1[SnapshotDate] ) )
        )

    Regards,

    Xiaoxin Sheng