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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
XiaozheZHANG
New Member

Select max_id in each date

Hi everyone,

 

Hope this message finds you all well. I would like to build incremental refresh in Power bi, hence, I leave sql statement empty when I link to sql server. Our database contains several report ids in each reporting date, but I only need max report id, I would like to make it in power query, hence native query will keep enabled. 

 

Datatable is like this, I need the data of report id of 4 in this date, could you please help me to make it in power query? 

 

Report IDDateValue
12024/5/221
12024/5/222
22024/5/223
32024/5/224
42024/5/225
42024/5/226
42024/5/227
42024/5/228
42024/5/229
42024/5/2210
1 REPLY 1
amanda2369weave
New Member

Expand the merged table to include only the rows with the maximum Report ID:

 

After the merge, you will see a new column with the merged table data.
Click on the expand icon (two arrows) next to the merged column and select only the MaxReportID to expand.
You can now filter the original table based on the MaxReportID to keep only the rows where the Report ID matches the MaxReportID.

 

Example in Power Query M Language:

Here is an example of how the steps would look in Power Query M code:

 

// Load the original table
let
    Source = Sql.Database("YourServerName", "YourDatabaseName"),
    OriginalTable = Source{[Schema="dbo",Item="YourTableName"]}[Data],

    // Group by Date to get the maximum Report ID for each date
    GroupedTable = Table.Group(OriginalTable, {"Date"}, {{"MaxReportID", each List.Max([Report ID]), type number}}),

    // Merge the original table with the grouped table to keep only the rows with the max Report ID
    MergedTable = Table.NestedJoin(OriginalTable, {"Date", "Report ID"}, GroupedTable, {"Date", "MaxReportID"}, "GroupedTable", JoinKind.Inner),

    // Expand the merged table
    ExpandedTable = Table.ExpandTableColumn(MergedTable, "GroupedTable", {"MaxReportID"}, {"MaxReportID"}),

    // Filter to keep only rows where Report ID equals MaxReportID
    FilteredTable = Table.SelectRows(ExpandedTable, each [Report ID] = [MaxReportID])
in
    FilteredTable

 

Explanation of the Code

Source: Connects to your SQL Server and loads the original table.
GroupedTable: Groups the data by Date and calculates the maximum Report ID for each date.
MergedTable: Merges the original table with the grouped table based on Date and Report ID.
ExpandedTable: Expands the merged column to include the MaxReportID.
FilteredTable: Filters the rows to keep only those where Report ID equals MaxReportID.


By following these steps and using the provided Power Query M code, you should be able to filter your data as required and set up incremental refresh in Power BI. mysedgwick app

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors