Forum Discussion

wadda7's avatar
wadda7
Icon for Helper I rankHelper I
4 years ago
Solved

How to Get Top 1 sales for today

Hello Everyone 

 

I have table for sales contains 

 

branchItemIdpriceQtyTotalDate
Br01011022001-01-2022
Br02011033001-01-2022

 

I want to filter the top sales according to the filed  (Total) for the current day  

 

Top branch sales 

Top Itemid Sales

 

  • If you want to perform this filter in Power Query, here is how you can do it.

     

    First, filter the date column for values equaling today.  Then filter the total column for the max value.

     

    BEFORE

     

    AFTER

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcioyMFTSUQIThgZAwgiEDcBCukZAZGBkpBSrA1ZohKLQGITRFcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [branch = _t, ItemId = _t, price = _t, Qty = _t, Total = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"branch", type text}, {"ItemId", Int64.Type}, {"price", Int64.Type}, {"Qty", Int64.Type}, {"Total", Int64.Type}, {"Date", type date}}),
        FilterForToday = Table.SelectRows(#"Changed Type", each Date.IsInCurrentDay([Date])),
        FilterForMax = Table.SelectRows(FilterForToday, let MaxValue = List.Max(FilterForToday[Total]) in each [Total] = MaxValue)
    in
        FilterForMax

1 Reply

  • If you want to perform this filter in Power Query, here is how you can do it.

     

    First, filter the date column for values equaling today.  Then filter the total column for the max value.

     

    BEFORE

     

    AFTER

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcioyMFTSUQIThgZAwgiEDcBCukZAZGBkpBSrA1ZohKLQGITRFcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [branch = _t, ItemId = _t, price = _t, Qty = _t, Total = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"branch", type text}, {"ItemId", Int64.Type}, {"price", Int64.Type}, {"Qty", Int64.Type}, {"Total", Int64.Type}, {"Date", type date}}),
        FilterForToday = Table.SelectRows(#"Changed Type", each Date.IsInCurrentDay([Date])),
        FilterForMax = Table.SelectRows(FilterForToday, let MaxValue = List.Max(FilterForToday[Total]) in each [Total] = MaxValue)
    in
        FilterForMax