Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello,
I've been working on a problem for hours and can't get any further! HELP ;-))
I have a list of users who belong to a group from a certain date.
If a user is moved to another group i have another entry with the new "from" date.
I need a new column (date_to) that says until when the user was in the group. If there is no newer entry the date of today should be entered.
user_number | group_id | date_from |
123 | xy | 10.11.2015 |
123 | ab | 05.07.2017 |
123 | de | 26.09.2019 |
456 | xy | 05.12.2016 |
456 | de | 03.03.2019 |
expected result:
user_number | group_id | date_from | date_to |
123 | xy | 10.11.2015 | 04.07.2017 |
123 | ab | 05.07.2017 | 25.09.2019 |
123 | de | 26.09.2019 | 12.12.2019 |
456 | xy | 05.12.2016 | 02.03.2019 |
456 | de | 03.03.2019 | 12.12.2019 |
Solved! Go to Solution.
You would need to add an index column in power query that allows you to look at the value from the previous row.
date_to =
VAR currentindex = 'Table'[Index]
VAR lastrowdate =
CALCULATE (
MAX ( 'Table'[date_from] ),
ALLEXCEPT ( 'Table', 'Table'[user_number] ),
FILTER ( 'Table', 'Table'[Index] = currentindex + 1 )
)
RETURN
IF (
[date_from]
= CALCULATE ( MAX ( [date_from] ), ALLEXCEPT ( 'Table', 'Table'[user_number] ) ),
TODAY (),
lastrowdate - 1
)
Sample pbix: https://microsoftapc-my.sharepoint.com/:u:/g/personal/v-pazhen_microsoft_com/EUYxhep3tNpGk3Tinz6bPQQ...
Paul
Best
You would need to add an index column in power query that allows you to look at the value from the previous row.
date_to =
VAR currentindex = 'Table'[Index]
VAR lastrowdate =
CALCULATE (
MAX ( 'Table'[date_from] ),
ALLEXCEPT ( 'Table', 'Table'[user_number] ),
FILTER ( 'Table', 'Table'[Index] = currentindex + 1 )
)
RETURN
IF (
[date_from]
= CALCULATE ( MAX ( [date_from] ), ALLEXCEPT ( 'Table', 'Table'[user_number] ) ),
TODAY (),
lastrowdate - 1
)
Sample pbix: https://microsoftapc-my.sharepoint.com/:u:/g/personal/v-pazhen_microsoft_com/EUYxhep3tNpGk3Tinz6bPQQ...
Paul
Best
Imke Feldmann has created a very useful function for shifting columns up and down:
The article above explains well how you can achieve your goal, but I will give a short summary. First, sort your table. Shift your date column with the mentioned function, the resulting column might be called date_from.Next. Then you can create a new column (like date_to = if date_from.Next = null then DateTime.LocalNow() else Date.AddDays(date_from.Next, -1)) that contains the data you want.
User | Count |
---|---|
103 | |
87 | |
77 | |
70 | |
69 |
User | Count |
---|---|
113 | |
99 | |
97 | |
72 | |
68 |