Forum Discussion
User check - new, removed, changed?
Hi
I'm starting to make a dashboard where we want to be able to check for changes in our user database - which we load on a monthly basis with new entries per month, something akin to this:
| ID | Name | Department | Manager | Phone | Date | Added | Removed | ChangedDept |
| 1 | Test | 111 | 3 | 111111 | 2020-01-01 | |||
| 2 | McFly | 222 | 3 | 222222 | 2020-01-01 | |||
| 3 | McBoss | 333 | 9 | 333333 | 2020-01-01 | |||
| 1 | Test | 222 | 3 | 111111 | 2020-02-01 | |||
| 3 | McBoss | 333 | 9 | 333444 | 2020-02-01 | |||
| 4 | McNew | 111 | 3 | 222222 | 2020-02-01 | |||
| 1 | Test | 222 | 3 | 111111 | 2020-03-01 | |||
| 3 | McBoss | 333 | 9 | 333444 | 2020-03-01 | |||
| 4 | McNew | 111 | 1 | 222222 | 2020-03-01 |
Now in Excel (where we do this right now) we just have a tab for each period and run simple VLOOKUPs to do this. But we want to automate it in PowerBI and create a dashboard with statistics and lists of who is affected by each change.
I want to do three things - all is done with checking within 1 month. So we don't want to compare data further back/forward.
1. Added ID - not present in previous month (unless earliest month is minimum value, just to stop getting thousands of adds first month we include in dataset). ID 4 in example above, should be given a field "Added" = Yes for the period 2020-02-01.
2. Removed ID - not present in next month (unless month being looked at is maximum month). ID 2 is removed in 2020-02-01 so should get a "Removed" field in period 2020-01-01, since it looks forward one month and it has data for 2020-02-01 and beyond. Unless there is an easy way to automatically insert a new entry for the month after it was removed in a dashboard?
3. Changed value - we use this for several fields, but understanding it for a single one is what I need. If Deptartment has changed from previous to next month, add a field "ChangedDept" = Yes. In example over ID 1 changed Department in 2020-02-01 and should get "Yes" in the field for that period, but not 2020-03-01 since it's not a change from the previous month.
EDIT: Ok, been finding ways to do this on my own but now it's more if those solutions are the most effective:
1. I added a PreviousMOnth and NextMonth calculated field - it gives what they suggest (DATEADD +1/-1,MONTH).
2. I then run IF with calculations to get the various data in new calculated fields:
Added =
IF (min(IDs[Date])=IDs[Date],"",if(
CALCULATE(
min(IDs[ID]),
filter (
all(IDs),
IDs[Date]=EARLIER(IDs[PreviousMonth])
&& IDs[ID]=earlier(IDs[ID])
))=IDs[ID],"","Added"))
Is it possible to move the Next/PreviousMonths into that expression? I tried just pasting them in but EARLIER doesn't work with on-the-fly calculations (i.e. EARLIER(DATEADD(IDs[DATE],-1,MONTH)) didn't work ).
- Anonymous6 years ago
Hi Anonymous ,
Create Calculated Column
Added = VAR _Previous_Date = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) ) ) VAR _MiNDate = CALCULATE ( MIN ( 'Table'[Date] ), ALL ( 'Table' ) ) RETURN IF ( ISBLANK ( _Previous_Date ) && 'Table'[Date] <> _MiNDate, "Added", "" )
Removed = var _Previous_Date = CALCULATE( MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date] > EARLIER('Table'[Date]))) Var _MAXDate = CALCULATE(MAX('Table'[Date]),ALL('Table')) RETURN // _Previous_Date IF(ISBLANK(_Previous_Date) && 'Table'[Date] <> _MAXDate , "Removed","")
Changed Department = var _Previous_Dept = CALCULATE( MAX('Table'[Department]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date] < EARLIER('Table'[Date]))) //Var _MAXDate = CALCULATE(MAX('Table'[Date]),ALL('Table')) RETURN //_Previous_Dept // _Previous_Date IF(NOT(ISBLANK(_Previous_Dept) )&& _Previous_Dept <> 'Table'[Department] , "Changed","")
Regards,
Harsh NathaniDid I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)
4 Replies
- v-xuding-msft
Community Support
Hi Anonymous ,
You could use a variable to define the previous month in the same formula, like this:
Added = var vPreviousMonth = DATEADD(IDs[Date],-1,MONTH) var vMinDate = MIN(IDs[Date]) var vID = CALCULATE( MIN(IDs[ID]), filter ( ALL(IDs), IDs[Date]=vPreviousMonth && IDs[ID]=EARLIER(IDs[ID]))) return IF (vMinDate=IDs[Date],"",if( vID=IDs[ID],"","Added"))- AnonymousNot applicable
Thanks, good to know for the future 🙂
If I try making this into a measure it fails - because it can't use EARLIER(IDs[ID]), but when I use it as a column it works fine.Why is that?
- AnonymousNot applicable
Hi Anonymous ,
Create Calculated Column
Added = VAR _Previous_Date = CALCULATE ( MAX ( 'Table'[Date] ), FILTER ( ALLEXCEPT ( 'Table', 'Table'[ID] ), 'Table'[Date] < EARLIER ( 'Table'[Date] ) ) ) VAR _MiNDate = CALCULATE ( MIN ( 'Table'[Date] ), ALL ( 'Table' ) ) RETURN IF ( ISBLANK ( _Previous_Date ) && 'Table'[Date] <> _MiNDate, "Added", "" )
Removed = var _Previous_Date = CALCULATE( MAX('Table'[Date]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date] > EARLIER('Table'[Date]))) Var _MAXDate = CALCULATE(MAX('Table'[Date]),ALL('Table')) RETURN // _Previous_Date IF(ISBLANK(_Previous_Date) && 'Table'[Date] <> _MAXDate , "Removed","")
Changed Department = var _Previous_Dept = CALCULATE( MAX('Table'[Department]),FILTER(ALLEXCEPT('Table','Table'[ID]),'Table'[Date] < EARLIER('Table'[Date]))) //Var _MAXDate = CALCULATE(MAX('Table'[Date]),ALL('Table')) RETURN //_Previous_Dept // _Previous_Date IF(NOT(ISBLANK(_Previous_Dept) )&& _Previous_Dept <> 'Table'[Department] , "Changed","")
Regards,
Harsh NathaniDid I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)