Thursday, February 27, 2025

How to Calculate Weighted Average Sales by Product over Year using DAX

How to Calculate Weighted Average Sales by Month over Year using DAX
Scenario:
Suppose we have a data Model as follows:


The relationships are as follows:


1) Weighted Average Sales by Month over Year:
We can calculate the Weighted Average Sales by Month over Year using below DAX Logics.

Net Sales = Sum(fct_Orders_Sample[Net_Sales])

Yearly Sales =
VAR _Annual_Sales =
CALCULATE(
    [Net Sales],
    ALLEXCEPT(dim_Calendar, dim_Calendar[DimYear])      
    )
VAR _Result = IF ( NOT(ISBLANK([Net Sales])), _Annual_Sales)
RETURN
_Result

Weighted Avg = DIVIDE([Net Sales], [Yearly Sales])

Weigh Avg Sales by Month =
VAR _SalesSummary =
    ADDCOLUMNS(
        SUMMARIZECOLUMNS(
            dim_Calendar[DimYear],
            dim_Calendar[MonthName],
            "NetSales", [Net Sales]        
        ),
   
    "WeighAvgByMonth",
        DIVIDE(
            [NetSales],
            CALCULATE(
                [Net Sales],
                ALLEXCEPT(dim_Calendar, dim_Calendar[DimYear]),
                ALLEXCEPT(dim_Calendar, dim_Calendar[MonthNo])
            )
        )
    )
VAR _Result =
    SUMX(_SalesSummary, [NetSales]*[WeighAvgByMonth])
RETURN
_Result

Result:


2) Weighted Average Sales by Product over Year:
We can calculate the Weighted Average Sales by Product using below DAX Logics.

Weigh Avg Sales by Product =
VAR _SalesSummary =
    ADDCOLUMNS(
        SUMMARIZECOLUMNS(
            dim_Calendar[DimYear],
            dim_Products[Product_ID],
            "NetSales", [Net Sales]        
        ),
   
    "WeighAvgByProd",
        DIVIDE(
            [NetSales],
            CALCULATE(
                [Net Sales],
                ALLEXCEPT(dim_Calendar, dim_Calendar[DimYear]),
                ALLEXCEPT(dim_Products, dim_Products[Product_ID])
            )
        )
    )
VAR _Result =
    SUMX(_SalesSummary, [NetSales]*[WeighAvgByProd])
RETURN
_Result

Result:


--------------------------------------------------------------------------------------------------------
Thanks, TAMATAM ; Business Intelligence & Analytics Professional
--------------------------------------------------------------------------------------------------------

No comments:

Post a Comment

Hi User, Thank You for visiting My Blog. If you wish, please share your genuine Feedback or comments only related to this Blog Posts. It is my humble request that, please do not post any Spam comments or Advertising kind of comments, which will be Ignored.

Featured Post from this Blog

How to compare Current Snapshot Data with Previous Snapshot in Power BI

How to Dynamically compare two Snapshots Data in Power BI Scenario: Suppose we have a sample Sales data, which is stored with Monthly Snapsh...

Popular Posts from this Blog