Forum Discussion
Anonymous
6 years agoNot applicable
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...
- 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.
Anonymous
6 years agoNot applicable
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
Ashish_Mathur
6 years agoSuper User
Hi,
You have not shown the Date column in your expected output. Also, please review the description in the total "closed since last snapshot date" row.
- Anonymous6 years agoNot applicable
Thanks Ashish_Mathur for your support through out and your point is valid as I forgot to provide Snapshot date column.
Thanks a lot again