Forum Discussion
Total difference between current and previous date
- 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" ) ) + 0Total 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" ) ) + 0Total 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.
Thanks again Ashish_Mathur
Result will be
| Total closed | total closed since last snapshot date | Total Open | Total Open since last snapshot date | Total calls | Running Total calls |
| 13 | 13 | 6 | 19 | 19 | 19 |
| 9 | 6 | 8 | 7 | 17 | 36 |
| 7 | 6 | 6 | 11 | 13 | 49 |
| 16 | 0 | 6 | 3 | 22 | 71 |
| 16 | 13 | 3 | 16 | 19 | 90 |
| 61 | 29 | 90 |
and definition of each column will be
| Measure | Definition |
| Total Closed | count for [State] = 'Closed' and [Created] does not matter |
| total closed since last snapshot date | count for [State] = 'Closed' and [Created] between current [Snapshot date] and last[Snapshot date] - for example on 1st Nov, current snapshot date is 1st Nov and previous is 23rd Oct so count all closed within these two dates where [created] column is after 23rd Oct and [Created] column is on or before 1st Nov |
| Total Open | count for State] = 'Open' and [Created] does not matter |
| Total Open since last snapshot date | count for [State] = 'Open' and [Created] between current [Snapshot date] and last[Snapshot date] |
| Total calls | Count for [Number] for each snapshot |
| Running Total calls | Running total of new column [Total calls] |
Thanks for support.
Regards
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.
- Anonymous6 years agoNot applicable
Thanks v-lid-msft , this worked perfectly where I tweaked a bit due to what was expected but it was nothing wrong with your DAX code. More imporantly I understood the concept of using variables and jumping between current and previous row. This concept will have long lasting impacts I believe because i am going to use it a lot.
Thanks a lot for your support.