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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
ercoc
New Member

Need help Optimizing a function: Return values from another row by previous date

Hi, first post and I know it could be more complete. I will do my best to provide more clarity as I find time. Thank you for your patience

 

Background:

I started working with a non-profit which has placed some unexpected restrictions on my work. Specifically, they require all ETL steps to take place in Power BI, steps that I'd normally outsource to SQL, etc. In general, I've been having fun trying to decide how best to balance computational costs between Power Query and DAX. E.g., I wouldn't have expected GroupBys to run so much faster in DAX. However, I'm having trouble optimizing an approach for a critical metric. The function and the following record expansion works as is but the refresh is very slow and often times-out making it too inefficient.

Question:
How can optimize this function for runtime?


Function: GetMaxPreviousMeeting

 

 

GetMaxPreviousMeeting = (currentRow, rows) => // function to efficiently capture  
               //  the previous meeting date/type for each speaker’s meeting.
  let
    filteredRows = Table.SelectRows(rows, each [speaker] = 
      currentRow[speaker] and [MeetingDate] < currentRow[MeetingDate]),
    maxDate = List.Max(filteredRows[MeetingDate]),
    meetingType = if maxDate <> null then 
      Table.First(Table.SelectRows(filteredRows, each [MeetingDate] = maxDate)) 
      [Type] else null
  in
    [PreviousMeetingDate = maxDate, PreviousMeetingType = meetingType]

=Table.AddColumn(Source, "Previous Meeting Info", 
    each #"Function:GetMaxPreviousMeeting"(_, Source))

= Table.ExpandRecordColumn(#"AddPreviousMeetingInfo", "Previous Meeting Info", 
    {"PreviousMeetingDate", "PreviousMeetingType"}, {"PreviousMeetingDate", 
    "PreviousMeetingType"})

 

 

 

 

Data:

The data consists of actions as rows, where one or more actions/rows can associated with the same meeting. A Unique meeting is identified by a unique combination of speaker, meeting date, and type. We want previous type and date to calculate a conditional deadline for the current row to find meeting timeliness.

 

Goal:

SpeakerTypeMeetingDateActionPreviousMeetingDatePreviousMeetingType
JohnA09/20/2023109/03/2023C
JohnA09/20/2023409/03/2023C
BobB09/13/20233nullnull
JohnA09/20/2023209/03/2023C
JohnC09/03/20233nullnull

 

Thank you!

1 ACCEPTED SOLUTION
ercoc
New Member

In the end, I decided to move the function to DAX instead and it works as intended without putting too much strain on end-user xp.

View solution in original post

1 REPLY 1
ercoc
New Member

In the end, I decided to move the function to DAX instead and it works as intended without putting too much strain on end-user xp.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.