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.
Hi,
I need to get the date on which MAX transaction happened during the each month. Till now I am unable to do so.
Example:
Tran_DT | TransactionCount |
23-02-2016 | 24 |
24-02-2016 | 39 |
25-02-2016 | 79 |
26-02-2016 | 96 |
27-02-2016 | 133 |
28-02-2016 | 141 |
29-02-2016 | 92 |
01-03-2016 | 78 |
02-03-2016 | 71 |
03-03-2016 | 117 |
04-03-2016 | 132 |
10-03-2016 | 266 |
11-03-2016 | 194 |
12-03-2016 | 165 |
13-03-2016 | 109 |
14-03-2016 | 253 |
12-04-2016 | 437 |
13-04-2016 | 397 |
14-04-2016 | 318 |
15-04-2016 | 260 |
Desired result:
Tran_DT | TransactionCount |
28-02-2016 | 141 |
10-03-2016 | 266 |
12-04-2016 | 437 |
Please help me on it.
Thanks & Regards,
Anupam
Solved! Go to Solution.
An alternative in - advanced - Power Query would be:
let Source = TransactionTable, Grouped = Table.Group(Source, {"Tran_DT"}, {{"AllData", each Table.MaxN(_,"TransactionCount",1), Value.Type(Source)}},null, (x,y) => let Sort1 = Value.Compare(Date.Year(x[Tran_DT]),Date.Year(y[Tran_DT])), Sort2 = if Sort1 <> 0 then Sort1 else Value.Compare(Date.Month(x[Tran_DT]),Date.Month(y[Tran_DT])) in Sort2), Removed = Table.RemoveColumns(Grouped,{"Tran_DT"}), Expanded = Table.ExpandTableColumn(Removed, "AllData", {"Tran_DT", "TransactionCount"}, {"Tran_DT", "TransactionCount"}) in Expanded
Basically it is "Group By" Tran_DT, but taking full advantage of Table.Group capacities;
Syntax of Table.Group:
Table.Group(table as table, key as any, aggregatedColumns as list, optional groupKind as nullable number, optional comparer as function) as table
A custom comparer function is provided to group on year/month (the inner "let .. in" part).
Parameter aggregatedColumns is adjusted so a table is returned with 1 record (the maximum TransactionCount) and with the same columntypes as table Source (this is the part Value.Type(Source)).
Note that the column "Tran_DT" after grouping does not contain the date on which the maximum was reached, so this column is removed.
The nested tables in column "AllData" contain exactly the information you require, so after expanding the nested tables, you have your result.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
111 | |
94 | |
80 | |
68 | |
59 |
User | Count |
---|---|
150 | |
119 | |
104 | |
87 | |
67 |