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
melina
Helper IV
Helper IV

Query editor filter the latest date

Hi All,

 

In my query editor, i have several of files.

The files are naming based on <plant_filename_date>

In the query editor, there are files from the same plant but different date.

 

Can i have filter in query editor, just for 1 file for the same plant with the lastest date?

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

You can Group By plant with operation "All Rows" and then adjust the generated code to have the maximum date selected.

 

let
    Source = Table1,
    #"Grouped Rows" = Table.Group(Source, {"Plant"}, {{"AllData", each Table.Max(_,"Date"), type record}}),
    #"Expanded AllData" = Table.ExpandRecordColumn(#"Grouped Rows", "AllData", {"FileName", "Date"}, {"FileName", "Date"})
in
    #"Expanded AllData"
Specializing in Power Query Formula Language (M)

View solution in original post

8 REPLIES 8
MarcelBeug
Community Champion
Community Champion

You can Group By plant with operation "All Rows" and then adjust the generated code to have the maximum date selected.

 

let
    Source = Table1,
    #"Grouped Rows" = Table.Group(Source, {"Plant"}, {{"AllData", each Table.Max(_,"Date"), type record}}),
    #"Expanded AllData" = Table.ExpandRecordColumn(#"Grouped Rows", "AllData", {"FileName", "Date"}, {"FileName", "Date"})
in
    #"Expanded AllData"
Specializing in Power Query Formula Language (M)

Hi,

 

I dont have plant and date column.

What i have just column for source name that contain <plantName_fileName_Date>

for example <F02_Shipping_19062017>

 

so do i need to extract this information first?

Yes. Propobably the best thing you can do is split the column on each underscore (_) and proceed from there.

Specializing in Power Query Formula Language (M)

Sorry, Could you help me to split for the plant and date? I had tried, but got the error.

Capture.PNG

Well, if you use DAX code in the query editor, it isn't going to work.

 

This would be Power Query code:

 

let
    Content = Table.FromColumns({{"F02_Shipping_19062017","F02_Shipping_19062018","F03_Shipping_19062017"}},type table[Name = text]),
    #"Split Column by Delimiter" = Table.SplitColumn(Content, "Name", Splitter.SplitTextByDelimiter("_", QuoteStyle.Csv), {"Name.1", "Name.2", "Name.3"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Name.1", type text}, {"Name.2", type text}, {"Name.3", Int64.Type}})
in
    #"Changed Type"

 

And this is how the last 2 steps were created:

Specializing in Power Query Formula Language (M)

what is file name?

Because i got null value?

So now you are asking me where you can find the filenames?

That feels like the world upside-down.

It is your data, so you should know where the filename is located.

Otherwise please share a screenshot that shows your column with filenames.

Are you sure you selected this column before splitting by underscore (_)?

Or did you just copy and paste my code somewhere into your query?

That ain't gonna work, that's why I created a video to illustrate the step to take.

Specializing in Power Query Formula Language (M)

Ok, i got the solution..!

Sorry and thanks!Smiley Happy

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.