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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jm_n
Frequent Visitor

Selecting and summarizing a value in the most recent row dynamically

Hi!

 

I haven't been able to find a straightforward answer to this particular challenge, so here it goes.

 

My data has ids, values (binary) and a date. One id can only have max one row per day.

 

How do I dynamically select the most recent rows for the ids in relation to my DateKey table and summarize the value column.

 

E.g. for the reporting date of 03/01/2018, value for x would be 0 and the value for y would be 1. I.e. summarized result=1. The desired end result is a visual showing the summarized result historically for every day.

 

idvaluedate
x001/01/2018
x102/01/2018
x003/01/2018
y102/01/2018
y004/01/2018

 

Thanks already in advance!

1 ACCEPTED SOLUTION
jm_n
Frequent Visitor

Hi! 

 

Thanks for the help. For some reason this didn't work. I ended up doing everything in SQL before taking the data to PowerBI. Basically:

 

  1. join all rows with a date table that contains reporting dates for the past year
  2. find and keep the row that is closest to the reporting date
  3. summarize values by reporting date

It is a bit heavy query but it works.

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @jm_n

 

Try this:

 

1. Place Table1[date] in the rows of a matrix visual

2. Create this measure and place it in values of the matrix:

 

Measure = 
VAR _SelectedDate = SELECTEDVALUE ( Table1[date] )
RETURN
    CALCULATE (
        SUMX (
            FILTER (
                Table1;
                Table1[date]
                    = CALCULATE (
                        MAX ( Table1[date] );
                        ALLEXCEPT ( Table1; Table1[id] );
                        FILTER ( ALL ( Table1[date] ); Table1[date] <= _SelectedDate )
                    )
            );
            Table1[value]
        );
        ALL ( Table1 )
    )

 

 

jm_n
Frequent Visitor

Hi! 

 

Thanks for the help. For some reason this didn't work. I ended up doing everything in SQL before taking the data to PowerBI. Basically:

 

  1. join all rows with a date table that contains reporting dates for the past year
  2. find and keep the row that is closest to the reporting date
  3. summarize values by reporting date

It is a bit heavy query but it works.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.