Forum Discussion
Help on How to Create a Measure Based on Start & End Date
- 4 years ago
Hi andybamber
Here is the sample file with the solution https://www.dropbox.com/t/J56gVd2IbetcntOR
For active users I assume a rolling number that, by time, increases when new users join and decreases when users leave. Therefore, when you say:
"So for instance if I looked at November 2021 i would see a distinct count of 2"
I would consider that you mean 2 members will be added to the moving (rolling) total. I hope this is what you mean.
One more thing need mention; this won't work properly if you have more than two start dates. The results won't be so accurate. If this is the case please provide data that reflects the actual scenario.New Users = IF ( HASONEVALUE ( Date_Table[MonthInCalendar] ), DISTINCTCOUNT ( 'Table'[User] ) )Active Users = VAR FirstDateInFilter = MIN ( Date_Table[Date] ) VAR LastDateInFilter = MAX ( Date_Table[Date] ) RETURN IF ( HASONEVALUE ( Date_Table[MonthInCalendar] ), CALCULATE ( SUMX ( VALUES ( 'Table'[User] ), VAR StartDate = CALCULATE ( MIN ( 'Table'[StartTimestamp] ) ) VAR EndDate = CALCULATE ( MAX ('Table'[EndTimestamp] ) ) RETURN IF ( StartDate <= LastDateInFilter && OR ( ISBLANK ( EndDate ), EndDate >= FirstDateInFilter ), 1, 0 ) ), REMOVEFILTERS ( Date_Table ) ) ) - 4 years ago
Hi andybamber
Here is the updated file https://www.dropbox.com/t/1g0PtekIviN7lpGU
Not sure if I correctly understand the what is required but I did the following:- I modified the code [New Users] in oder to include duplicates in the count. So instead of counting user ID's we now count the number of rows.
- The [Active Users] Measure has been updated accordingly.
- The [Leaving Users] Measure has been added.
- Fixed the Total to show correct values.
I hope this satisfies your requirements.
New Users = SUMX ( VALUES ( Date_Table[MonthInCalendar] ), CALCULATE ( COUNTROWS ( 'Table' ) ) )Leaving Users = VAR CurrentDateRange = VALUES ( Date_Table[Date] ) RETURN CALCULATE ( SUMX ( 'Table', VAR EndDate = 'Table'[EndTimestamp] RETURN IF ( DATE ( YEAR ( EndDate ), MONTH ( EndDate ), DAY ( EndDate ) ) IN CurrentDateRange && NOT ISBLANK ( 'Table'[EndTimestamp] ), 1 ) ), REMOVEFILTERS ( Date_Table ) )Active Users = VAR LastDateInFilter = MAX ( Date_Table[Date] ) VAR FirstDateInFilter = DATE ( YEAR ( LastDateInFilter ), MONTH ( LastDateInFilter ) - 1, 1 ) RETURN CALCULATE ( SUMX ( 'Table', VAR StartDate = 'Table'[StartTimestamp] VAR EndDate = 'Table'[EndTimestamp] RETURN IF ( StartDate <= LastDateInFilter && OR ( ISBLANK ( EndDate ), EndDate >= FirstDateInFilter ), 1 ) ), REMOVEFILTERS ( Date_Table ) )Have a great day!
I'll look into it and get baxk to you. Please remide me in a private message if I didn't
- tamerj14 years ago
Community Champion
Hi andybamber
Here is the updated file https://www.dropbox.com/t/1g0PtekIviN7lpGU
Not sure if I correctly understand the what is required but I did the following:- I modified the code [New Users] in oder to include duplicates in the count. So instead of counting user ID's we now count the number of rows.
- The [Active Users] Measure has been updated accordingly.
- The [Leaving Users] Measure has been added.
- Fixed the Total to show correct values.
I hope this satisfies your requirements.
New Users = SUMX ( VALUES ( Date_Table[MonthInCalendar] ), CALCULATE ( COUNTROWS ( 'Table' ) ) )Leaving Users = VAR CurrentDateRange = VALUES ( Date_Table[Date] ) RETURN CALCULATE ( SUMX ( 'Table', VAR EndDate = 'Table'[EndTimestamp] RETURN IF ( DATE ( YEAR ( EndDate ), MONTH ( EndDate ), DAY ( EndDate ) ) IN CurrentDateRange && NOT ISBLANK ( 'Table'[EndTimestamp] ), 1 ) ), REMOVEFILTERS ( Date_Table ) )Active Users = VAR LastDateInFilter = MAX ( Date_Table[Date] ) VAR FirstDateInFilter = DATE ( YEAR ( LastDateInFilter ), MONTH ( LastDateInFilter ) - 1, 1 ) RETURN CALCULATE ( SUMX ( 'Table', VAR StartDate = 'Table'[StartTimestamp] VAR EndDate = 'Table'[EndTimestamp] RETURN IF ( StartDate <= LastDateInFilter && OR ( ISBLANK ( EndDate ), EndDate >= FirstDateInFilter ), 1 ) ), REMOVEFILTERS ( Date_Table ) )Have a great day!