Forum Discussion

mcollins's avatar
mcollins
Frequent Visitor
8 years ago
Solved

Copy Table & Summarize

I want to create a new table from an existing table but utilizing only a few of the columns.  I then want to sum up the amount of hours in the one column based upon month and year.   I can copy the...
  • v-jiascu-msft's avatar
    8 years ago

    Hi mcollins,

     

    Which result do you want exactly? You can try the formulas below.

     

    Table 2 =
    SUMMARIZE (
        ADDCOLUMNS (
            FILTER (
                SUMMARIZE (
                    'Detailed Ledger',
                    'Detailed Ledger'[Project ID],
                    'Detailed Ledger'[Hours],
                    'Detailed Ledger'[Cost Code],
                    'Detailed Ledger'[Date]
                ),
                NOT ISBLANK ( 'Detailed Ledger'[Hours] )
            ),
            "Year", YEAR ( [Date] ),
            "Month", MONTH ( [Date] )
        ),
        [Year],
        [Month],
        "sumHours", SUM ( 'Detailed Ledger'[Hours] )
    )

     

     

     

     

     

     

     

     

     

     

     

     

    Table =
    ADDCOLUMNS (
        FILTER (
            SUMMARIZE (
                'Detailed Ledger',
                'Detailed Ledger'[Project ID],
                'Detailed Ledger'[Hours],
                'Detailed Ledger'[Cost Code],
                'Detailed Ledger'[Date]
            ),
            NOT ISBLANK ( 'Detailed Ledger'[Hours] )
        ),
        "Year", YEAR ( [Date] ),
        "Month", MONTH ( [Date] ),
        "Trade", SWITCH (
            TRUE (),
            [Cost Code] < 20000, "GC",
            [Cost Code] < 40000, "C",
            [Cost Code] < 110000, "A",
            [Cost Code] < 120000, "M",
            [Cost Code] < 130000, "A",
            [Cost Code] < 140000, "M",
            [Cost Code] < 150000, "A",
            [Cost Code] < 160000, "M",
            [Cost Code] < 170000, "E",
            [Cost Code] < 180000, "17",
            "0"
        )
    )

     

    Best Regards,

    Dale

  • mcollins's avatar
    mcollins
    8 years ago

    Thanks v-jiascu-msft, I combined the two statements to get what I wanted:

     

    EVALUATE SUMMARIZE (
        ADDCOLUMNS (
            FILTER (
                SUMMARIZE (
                    'Detailed Ledger',
                    'Detailed Ledger'[Project ID],
                    'Detailed Ledger'[Hours],
                    'Detailed Ledger'[Cost Code],
                    'Detailed Ledger'[Date]
                ),
                NOT ISBLANK ( 'Detailed Ledger'[Hours] )
            ),
            "Year", YEAR ( [Date] ),
            "Month", MONTH ( [Date] ),
            "Trade", SWITCH (
                TRUE (),
                [Cost Code] < 20000, "GC",
                [Cost Code] < 40000, "C",
                [Cost Code] < 110000, "A",
                [Cost Code] < 120000, "M",
                [Cost Code] < 130000, "A",
                [Cost Code] < 140000, "M",
                [Cost Code] < 150000, "A",
                [Cost Code] < 160000, "M",
                [Cost Code] < 170000, "E",
                [Cost Code] < 180000, "17",
                "0"
            )
        ),
        [Project ID],
        [Year],
        [Month],
        [Trade],
        "sumHours", SUM ( 'Detailed Ledger'[Hours] )
    )