Forum Discussion
nicolasvc
Helper III
5 years agogroup data by minimum value
I have a table the id of the store, year, month, the number of the week in the year, and the corresponding sales, but I need to have only the first week of the month per store. store year month...
- Anonymous5 years ago
Hi nicolasvc
I think you want to create a calcualte table to show frist week of each month based on "Table 1".
Try my code.
Table 2 = VAR _T1 = SUMMARIZE ( 'Table 1', 'Table 1'[Store], 'Table 1'[Year], 'Table 1'[Month], "MinWeekEachMonth", CALCULATE ( MIN ( 'Table 1'[Week] ), FILTER ( 'Table 1', AND ( 'Table 1'[Year] = EARLIER ( 'Table 1'[Year] ), 'Table 1'[Month] = EARLIER ( 'Table 1'[Month] ) ) ) ) ) VAR _T2 = ADDCOLUMNS ( _T1, "Sales", CALCULATE ( SUM ( 'Table 1'[Sales] ), FILTER ( 'Table 1', 'Table 1'[Store] = EARLIER ( [Store] ) && 'Table 1'[Year] = EARLIER ( [Year] ) && 'Table 1'[Month] = EARLIER ( [Month] ) && 'Table 1'[Week] = EARLIER ( [MinWeekEachMonth] ) ) ) ) RETURN _T2Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
parry2k
Super User
5 years agonicolasvc I see, no issue, we can still work on it, so you want to get first week record of each month.
- nicolasvc5 years ago
Helper III
Exactly, in power query I could do it by grouping the columns I wanted and using the MIN function in the week. I tried to do something similar in DAX and it didn't work.
- nicolasvc5 years ago
Helper III
I made a patch solution, grouped the week into power query and then use lookupvalue to match between the columns.