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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How can I get Minimum Date For category and sales DAX

Hello everyone,

 

I would like to get the Minimum date of each category and it's sales.

 

Conditions for calculation:

1) Get Minimum date   for each category and it's Sales

2) Exclude where Category = "07-LFN"

3) Show only current financial year records where financial year starts from July to June.

 

 

Deeintu_0-1644218488964.png

 

Thanks in advance

Dee

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

If you want it in Power Query , please try

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5RCoAwCIDhu+y5kbqV2wV6ihq9Rve/RjoJYvgmfOjvfQfA2FoLUyAgmnEGkhkhYwrP5HBSzonY56zM4sYU92v7McpcoYCvPc0LV59Tn6sc6cxx3w5jFEbdZpYPRnXKo1qZvvLIVl6/chE+jUHLehux5OpzP06Lbj8v", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Date = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Date", type date}, {"Sales", Int64.Type}}),
    #"Filtered Rows"= Table.SelectRows(#"Changed Type", each [Category]<>"07-LFN" and Date.Year([Date])=Date.Year(DateTime.LocalNow()) ),
    
     #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Category"}, {{"Count", each _, Value.Type(#"Filtered Rows")}, {"Minimum Date", each List.Min([Date]) }}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Date", "Sales"}, {"Date", "Sales"}),
    #"Filtered"=Table.SelectRows(#"Expanded Count", each [Date]=[Minimum Date]),
    #"Removed Columns" = Table.RemoveColumns(Filtered,{"Minimum Date"})
in
     #"Removed Columns"

Output:

Eyelyn9_0-1644482649790.png

 

Or:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5RCoAwCIDhu+y5kbqV2wV6ihq9Rve/RjoJYvgmfOjvfQfA2FoLUyAgmnEGkhkhYwrP5HBSzonY56zM4sYU92v7McpcoYCvPc0LV59Tn6sc6cxx3w5jFEbdZpYPRnXKo1qZvvLIVl6/chE+jUHLehux5OpzP06Lbj8v", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Date = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Date", type date}, {"Sales", Int64.Type}}),
    #"Filtered Rows"= Table.SelectRows(#"Changed Type", each [Category]<>"07-LFN" and Date.Year([Date])=Date.Year(DateTime.LocalNow()) ),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Category"}, {{"Count", each _, type table [Category=nullable text, Date=nullable date, Sales=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Min([Count],"Date")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Removed Columns", "Custom", {"Date", "Sales"}, {"Date", "Sales"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Category", type text}, {"Date", type date}, {"Sales", Int64.Type}})
in
    #"Changed Type1"

 Output:

Eyelyn9_2-1644482885910.png

 

Best Regards,
Eyelyn Qin
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

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

If you want it in Power Query , please try

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5RCoAwCIDhu+y5kbqV2wV6ihq9Rve/RjoJYvgmfOjvfQfA2FoLUyAgmnEGkhkhYwrP5HBSzonY56zM4sYU92v7McpcoYCvPc0LV59Tn6sc6cxx3w5jFEbdZpYPRnXKo1qZvvLIVl6/chE+jUHLehux5OpzP06Lbj8v", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Date = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Date", type date}, {"Sales", Int64.Type}}),
    #"Filtered Rows"= Table.SelectRows(#"Changed Type", each [Category]<>"07-LFN" and Date.Year([Date])=Date.Year(DateTime.LocalNow()) ),
    
     #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Category"}, {{"Count", each _, Value.Type(#"Filtered Rows")}, {"Minimum Date", each List.Min([Date]) }}),
    #"Expanded Count" = Table.ExpandTableColumn(#"Grouped Rows", "Count", {"Date", "Sales"}, {"Date", "Sales"}),
    #"Filtered"=Table.SelectRows(#"Expanded Count", each [Date]=[Minimum Date]),
    #"Removed Columns" = Table.RemoveColumns(Filtered,{"Minimum Date"})
in
     #"Removed Columns"

Output:

Eyelyn9_0-1644482649790.png

 

Or:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bc5RCoAwCIDhu+y5kbqV2wV6ihq9Rve/RjoJYvgmfOjvfQfA2FoLUyAgmnEGkhkhYwrP5HBSzonY56zM4sYU92v7McpcoYCvPc0LV59Tn6sc6cxx3w5jFEbdZpYPRnXKo1qZvvLIVl6/chE+jUHLehux5OpzP06Lbj8v", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Category = _t, Date = _t, Sales = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Date", type date}, {"Sales", Int64.Type}}),
    #"Filtered Rows"= Table.SelectRows(#"Changed Type", each [Category]<>"07-LFN" and Date.Year([Date])=Date.Year(DateTime.LocalNow()) ),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Category"}, {{"Count", each _, type table [Category=nullable text, Date=nullable date, Sales=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Min([Count],"Date")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Removed Columns", "Custom", {"Date", "Sales"}, {"Date", "Sales"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"Category", type text}, {"Date", type date}, {"Sales", Int64.Type}})
in
    #"Changed Type1"

 Output:

Eyelyn9_2-1644482885910.png

 

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

TomMartens
Super User
Super User

Hey @Anonymous ,

 

consider to re-create the sample data in a way that can be easily used in Power BI. As you are using dates consider creating a Power BI file, upload the pbix to onedrive or dropbox and share the link.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Hi @TomMartens ,

 

I managed to acheive it in power query.

 

Thanks

Dee

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.