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...
  • v-lid-msft's avatar
    v-lid-msft
    6 years ago

    Hi Anonymous ,

     

    We can use the following measure to meet your requirement:

     

    Total Closed = 
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Number] ),
        FILTER ( 'Table', [State] = "Closed" )
    )

     

    total closed since last snapshot date = 
    VAR currentSnapshotDate =
        MAX ( 'Table'[SnapshotDate] )
    VAR lastSnapshotDate =
        CALCULATE (
            MAX ( 'Table'[SnapshotDate] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[SnapshotDate] < currentSnapshotDate )
        )
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[Number] ),
            FILTER (
                'Table',
                'Table'[Created].[Date] <= currentSnapshotDate
                    && 'Table'[Created].[Date] > lastSnapshotDate
                    && 'Table'[State] = "Closed"
            )
        ) + 0

     

    Total Open = 
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[Number] ),
        FILTER ( 'Table', [State] = "Open" )
    )

     

    total open since last snapshot date = 
    VAR currentSnapshotDate =
        MAX ( 'Table'[SnapshotDate] )
    VAR lastSnapshotDate =
        CALCULATE (
            MAX ( 'Table'[SnapshotDate] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[SnapshotDate] < currentSnapshotDate )
        )
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[Number] ),
            FILTER (
                'Table',
                'Table'[Created].[Date] <= currentSnapshotDate
                    && 'Table'[Created].[Date] > lastSnapshotDate
                    && 'Table'[State] = "Open"
            )
        ) + 0

     

    Total calls = 
    DISTINCTCOUNT('Table'[Number])

     

    Running Total calls = 
    VAR snapshotDate =
        MAX ( 'Table'[SnapshotDate] )
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( 'Table'[Number] ),
            FILTER ( ALLSELECTED ( 'Table' ), [SnapshotDate] <= snapshotDate )
        )

     

     


    BTW, pbix as attached.

     

    Best regards,

    Community Support Team _ Dong Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.