Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
100 | |
81 | |
70 | |
62 |
User | Count |
---|---|
148 | |
116 | |
104 | |
90 | |
65 |