Forum Discussion

nicolasvc's avatar
nicolasvc
Icon for Helper III rankHelper III
5 years ago
Solved

group 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...
  • Anonymous's avatar
    Anonymous
    5 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
        _T2

    Result is as below.

    Best Regards,
    Rico Zhou

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.