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
Deeintu
Helper I
Helper I

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
v-eqin-msft
Community Support
Community Support

Hi @Deeintu ,

 

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
v-eqin-msft
Community Support
Community Support

Hi @Deeintu ,

 

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 @Deeintu ,

 

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

Hi @TomMartens ,

 

I managed to acheive it in power query.

 

Thanks

Dee

 

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.