Sunday, July 5, 2020

SUMMARIZE AND SUMMARIZECOLUMNS in Power BI

Today we are going to see SUMMARIZE, ADDCOLUMNS and SUMMARIZECOLUMNS:

Extension columns are columns that you add to existing tables. You can obtain extension columns by 
using both ADDCOLUMNS and SUMMARIZE. Basically these functions adds columns / tables over the conditions applied.

For example, the following query adds a Year Production column to the rows returned from the Product table.

EVALUATE
ADDCOLUMNS(
    Product,
    "Year Production", YEAR( Product[Product Start Date] )
)

In below query, you can count the number of products for each product category by using the following query

EVALUATE
SUMMARIZE(
    Product,
    Product[Product Category Name],
    "Products", COUNTROWS( Product )
)


For performance reasons it is better to add ADDCOLUMNS() outside. 

EVALUATE
ADDCOLUMNS(
    SUMMARIZE(
        Product,
        Product[Product Name],
        Product[Product Start Date]
    ),
    "Year Production", YEAR( Product[Product Start Date] )
)
SUMMARIZECOLUMNSReturns a summary table over a set of groups.

Below query returns the sumofsales for calendar year and category name
Summarize =
SUMMARIZECOLUMNS(
    'Calendar'[Year],
    Categories[CategoryName],
    "sumofsales", [Sales])


Thanks, :)

No comments:

Post a Comment