Forum Discussion
Getting a date depending on previous rows
Hi all,
Below are 3 sample datasets, ordered by ValidFrom descending.
I'm trying to get Power BI to show in the far right column, the date since which a group of the same ID's is currently marked 1.
It is current when ValidTo = Blank.
However, in case there are two or more rows right below the current row that are also marked 1, Power BI should give the earliest ValidFrom date of those rows.
In case the most recent row is marked 0, the far right column should show no date:
How might this be achieved in a measure or calculated column?
Any suggestions would be very welcome.
Thank you very muchv-henryk-mstf for your suggestions. They were a good help although they did not completely meet all the requirements needed for this particular project.
I now created a duplicate table and added in this duplicate table, an index column grouped by ID:
https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query
https://www.youtube.com/watch?v=jmzTHZK5z7gTo create this index I followed these steps from the above links:
- Sort the column ValidFrom as Ascending (this makes Power BI allocate the highest Index to the latest ValidFrom. This will be important later for referring to previous row)
- Group the data by ID.
- Add custom column using ‘ Table.AddIndexColumn’ . Make sure Power BI has allocated the highest Index number to the latest ValidFrom date.
- Right click > Remove other columns.
- Expand table.
- Detect data type.
That created this table as a duplicate from the original.
Next, I created in this duplicate table, a calculated column to refer to the previous row, and continued from there:
2 Replies
- v-henryk-mstfCommunity Support
Hi GKJARC ,
Try the formula like below:
Column = MAXX ( FILTER ( Table1, Table1[Marked] = 1 && Table1[Vaildto] = BLANK () ), Table1[Validfrom] )Column = MAXX ( FILTER ( ALL ( Table2 ), Table2[Marked] = 1 && Table2[Vaildto] <> BLANK () && Table2[Validfrom] >= EARLIER ( Table2[Validfrom] ) ), Table2[Validfrom] )If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.
Best Regards,
Henry
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- GKJARCResolver I
Thank you very muchv-henryk-mstf for your suggestions. They were a good help although they did not completely meet all the requirements needed for this particular project.
I now created a duplicate table and added in this duplicate table, an index column grouped by ID:
https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query
https://www.youtube.com/watch?v=jmzTHZK5z7gTo create this index I followed these steps from the above links:
- Sort the column ValidFrom as Ascending (this makes Power BI allocate the highest Index to the latest ValidFrom. This will be important later for referring to previous row)
- Group the data by ID.
- Add custom column using ‘ Table.AddIndexColumn’ . Make sure Power BI has allocated the highest Index number to the latest ValidFrom date.
- Right click > Remove other columns.
- Expand table.
- Detect data type.
That created this table as a duplicate from the original.
Next, I created in this duplicate table, a calculated column to refer to the previous row, and continued from there: