Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
GKJARC
Resolver I
Resolver I

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.
GKJARC_2-1648490348509.png

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. 
GKJARC_1-1648490320702.png

In case the most recent row is marked 0, the far right column should show no date:

GKJARC_3-1648490389815.png


How might this be achieved in a measure or calculated column?

Any suggestions would be very welcome.

1 ACCEPTED SOLUTION

Thank you very much@v-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=jmzTHZK5z7g

To create this index I followed these steps from the above links:

  1. 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)
  2. Group the data by ID.
  3. Add custom column using ‘ Table.AddIndexColumn’ . Make sure Power BI has allocated the highest Index number to the latest ValidFrom date.
  4. Right click > Remove other columns.
  5. Expand table.
  6. Detect data type.

That created this table as a duplicate from the original.

GKJARC_1-1648984728027.png

Next, I created in this duplicate table, a calculated column to refer to the previous row, and continued from there:

GKJARC_2-1648984819800.png

 

View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community 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]
)

vhenrykmstf_0-1648704534835.pngvhenrykmstf_1-1648704572229.png

 

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.

Thank you very much@v-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=jmzTHZK5z7g

To create this index I followed these steps from the above links:

  1. 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)
  2. Group the data by ID.
  3. Add custom column using ‘ Table.AddIndexColumn’ . Make sure Power BI has allocated the highest Index number to the latest ValidFrom date.
  4. Right click > Remove other columns.
  5. Expand table.
  6. Detect data type.

That created this table as a duplicate from the original.

GKJARC_1-1648984728027.png

Next, I created in this duplicate table, a calculated column to refer to the previous row, and continued from there:

GKJARC_2-1648984819800.png

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.