Forum Discussion

rylach's avatar
rylach
Icon for Helper II rankHelper II
6 years ago
Solved

Calculating amount given for period - from one row

Hi, I have the following table, containing an amount per day in the following format: item (amount_per_day regards particular item) start_date end_date include_holidays (true/false), calenda...
  • v-zhenbw-msft's avatar
    v-zhenbw-msft
    6 years ago

    Hi rylach ,

     

    We can use the following steps to meet your requirement.

     

    1. Create a date table first.

     

    Date = CALENDARAUTO()

     

     

    2. Then create four columns in Table to calculate the start date and end date.

     

    Next_start_week = [start_date]+7
    Next_end_week = [end_date]+7
    R_start_week = [Next_start_week]+7
    R_end_week = [Next_end_week]+7

     

     

    3. At last we can create a calculate table and create a table visual to get the result,

     

    Table 2 = 
    VAR x =
        SUMMARIZE (
            FILTER (
                CROSSJOIN ( 'Date', 'Table' ),
                'Table'[start_date] <= 'Date'[Date]
                    && 'Table'[end_date] >= 'Date'[Date]
            ),
            'Table'[item],
            [Date],
            'Table'[amount per day]
        )
    VAR y =
        SUMMARIZE (
            FILTER (
                CROSSJOIN ( 'Date', 'Table' ),
                'Table'[Next_start_week] <= 'Date'[Date]
                    && 'Table'[Next_end_week] >= 'Date'[Date]
            ),
            'Table'[item],
            [Date],
            'Table'[amount per day]
        )
    VAR z =
        SUMMARIZE (
            FILTER (
                CROSSJOIN ( 'Date', 'Table' ),
                'Table'[R_start_week] <= 'Date'[Date]
                    && 'Table'[R_end_week] >= 'Date'[Date]
            ),
            'Table'[item],
            [Date],
            'Table'[amount per day]
        )
    RETURN
    ADDCOLUMNS ( UNION ( x, y, z ), "month", FORMAT ( [Date], "mmmm" ) )

     

     

     

    If it doesnโ€™t meet your requirement, could you please show the exact expected result based on the table that you have shared?

    BTW, pbix as attached.

     

    Best regards,

     

    Community Support Team _ zhenbw

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