Search code examples
powerbidaxpowerpivotssas-tabular

DAX language- Microsoft Power BI - SUMMARIZE inside SELECTCOLUMNS - simple syntax


I have a situation below (Power BI - DAX) in which I am trying to SUMMARIZE a table called Product with a SUM aggregation to get the total cost of all products in each Category; but then I have to change the column name of one or two columns in the summarized result set.

I have written the below code to develop a calculated table:

ProductCategoryCostCT = SELECTCOLUMNS (

                                       SUMMARIZE(

                                                 Product,

                                                 Product[Category],

                                                 "TotalCostOfAllProductsInThisCategory", SUM(Product[ProductCost])

                                                ),

                                      "CategoryName", Product[Category],

                                      "Cost",  Product[TotalCostOfAllProductsInThisCategory]

                                     )

The above code throws an error. Can someone help me correct this ? This may be pedestrian to many of you!

(The source Product table has ProductCost column at the individual Product level, with Category as another column in the same table)


Solution

  • ProductCategoryCostCT =  SUMMARIZE(
    
                                        SELECTCOLUMNS(
    
                                                       Product,
    
                                                       "CategoryName", Product[Category],
                                                       "ProductCost", Product[ProductCost]
    
                                                     ),
    
                                        [CategoryName],
    
                                        "Cost", SUM(Product[ProductCost])
    
                                      )