Forum Discussion
wadda7
Helper I
4 years agoHow to Get Top 1 sales for today
Hello Everyone
I have table for sales contains
| branch | ItemId | price | Qty | Total | Date |
| Br01 | 01 | 10 | 2 | 20 | 01-01-2022 |
| Br02 | 01 | 10 | 3 | 30 | 01-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
- jennratten
Super User
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