Forum Discussion
Month MAX record
- 9 years ago
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 ExpandedBasically 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.
anupampandey if you say its not working you need to give me more information.
firstly please post the code you created
then screen shot how you were viewing it detailing the issue
you can read more about last date here, https://msdn.microsoft.com/en-us/library/ee634380.aspx
when you say its not working, what is not working? please provide me with details, i can't help you solve your issue if you dont give me information to work with
vanessafvg I am using below code.
C1 = CALCULATE(MAX('Z test1'[CountTran]),LASTDATE(Calender[DateKey]))
I have got the result as explained by you.
This result is count of transactions done on lastdate of all the months during the year. I am looking for the maximum transactions done in those months and date pertains to that max count transaction.
Below is the image: left side is the sample data and right side is my desired output for which I am looking for solution.
Sample
Also above sample is summarised one. Actually I have put this on my sales fact table which is having 2 million records where each date is getting repeated. One any particular date there are thousands of transactions which first need to calculated date wise and than taking out the max.
Thanks & Regards,
Anupam
- vanessafvg9 years agoCommunity Champion
i understand the requirements, i dont understand why what i gave you isnt working, i want you to show me the results of the dax code i gave you
anupampandey please provide the results so i can see what is going on
- anupampandey9 years agoHelper III
vanessafvg your given DAX is giving me the result. This result showing the count of transaction only for last day of month.
Result of DAX provided
I this result if we can show the count of max transaction in that month rather than of lastdate that would be best and desired also.
Regards,
Anupam
- vanessafvg9 years agoCommunity Champion
anupampandey the max transaction date is the same as lastdate in this context if you use the month on your graph
please can you rather put in a matrix with the month and the measure as its hard to know what data is contained there