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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
bml123
Post Patron
Post Patron

Min date with a condition Power query

Hi,

 

I have a measure like this

 

Active_date = CALCULATE(Min(Table[ExtractDate]),Table[Status]="Active")
 
How do I achieve this in Power query?
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @bml123 ,

 

I used group by and Table.Min to get the dates.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckwuySxLVdJRMjIwMtI10jUFMg2VYnUwZUxATKwyZkCmMVjGMy8RRc5Q1wjINMEhZwhkmuKQMwYyzZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Status = _t, ExtractDate = _t, Index = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status", type text}, {"ExtractDate", type date}, {"Index", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Status"}, {{"Count", each _, type table [Status=nullable text, ExtractDate=nullable date, Index=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Min([Count],"ExtractDate")),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"ExtractDate"}, {"ExtractDate"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"ExtractDate", "ActiveMinDate"}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Renamed Columns", "Count", {"ExtractDate", "Index"}, {"ExtractDate", "Index"})
in
    #"Expanded Count"

Input:

vstephenmsft_1-1657617769993.png

Output:

vstephenmsft_0-1657617721456.png

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @bml123 ,

 

I used group by and Table.Min to get the dates.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WckwuySxLVdJRMjIwMtI10jUFMg2VYnUwZUxATKwyZkCmMVjGMy8RRc5Q1wjINMEhZwhkmuKQMwYyzZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Status = _t, ExtractDate = _t, Index = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status", type text}, {"ExtractDate", type date}, {"Index", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Status"}, {{"Count", each _, type table [Status=nullable text, ExtractDate=nullable date, Index=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Min([Count],"ExtractDate")),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Added Custom", "Custom", {"ExtractDate"}, {"ExtractDate"}),
    #"Renamed Columns" = Table.RenameColumns(#"Expanded Custom",{{"ExtractDate", "ActiveMinDate"}}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Renamed Columns", "Count", {"ExtractDate", "Index"}, {"ExtractDate", "Index"})
in
    #"Expanded Count"

Input:

vstephenmsft_1-1657617769993.png

Output:

vstephenmsft_0-1657617721456.png

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@bml123 , In Power Query you can only create a column not measure

 

Power Query - List.Min and List.MinN https://youtu.be/9wYdttOPWaQ

 

You can List.Select https://docs.microsoft.com/en-us/powerquery-m/list-select

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.