Forum Discussion

Sandeep_PowerBI's avatar
Sandeep_PowerBI
Frequent Visitor
3 years ago
Solved

SumProduct with Power BI

Hi Team,

 

Please help me with SUMPRODUCT similar with excel in DAX measure... Below are my Actuals in Main Category and Lines. How to get weighted average using SUMPRODUCT logic in DAX command?

I want to get below highlight output using DAX command... 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Sandeep_PowerBI ,

     

    In Power BI, you need to use unpivot and pivot for your data first, and then you can perform calculations.

    After transformation, the data is as follows.

    Create this measure:

    Measure =
    VAR _table =
        SUMMARIZE (
            'Table',
            [Line],
            [ABC],
            [HMP],
            "Product", SUM ( 'Table'[ABC] ) * SUM ( 'Table'[HMP] )
        )
    RETURN
        DIVIDE (
            SUMX ( _table, [Product] ),
            SUMX ( FILTER ( ALL ( 'Table' ), [Line] = MAX ( 'Table'[Line] ) ), [HMP] )
        )
    

     

       

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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

     

11 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Sandeep_PowerBI ,

     

    In Power BI, you need to use unpivot and pivot for your data first, and then you can perform calculations.

    After transformation, the data is as follows.

    Create this measure:

    Measure =
    VAR _table =
        SUMMARIZE (
            'Table',
            [Line],
            [ABC],
            [HMP],
            "Product", SUM ( 'Table'[ABC] ) * SUM ( 'Table'[HMP] )
        )
    RETURN
        DIVIDE (
            SUMX ( _table, [Product] ),
            SUMX ( FILTER ( ALL ( 'Table' ), [Line] = MAX ( 'Table'[Line] ) ), [HMP] )
        )
    

     

       

                                                                                                                                                             

    Best Regards,

    Stephen Tao

     

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

     

      • some_bih's avatar
        some_bih
        Icon for Community Champion rankCommunity Champion

        Hi Sandeep_PowerBI as I wrote, I organize your excel data into different structure /unpivoting and basically rename your Actual to Weight to follow calculation logic.

        In red below you can find example your and mine data.

         

         

    • Sandeep_PowerBI's avatar
      Sandeep_PowerBI
      Frequent Visitor

      Hi,

       

      Thanks for response,

      Actually separating in 3 columns is fine. Done in Transaformation unpivot. but, the same calculation is not matching to my requiremet.  I want to calculate weighted Average value using DAX...

      =SUMPRODUCT(D2:O2,D5:O5)/SUM(D2:O2) - using Excel

      =SUMPRODUCT(HMP(D2:O2), ABC(D5:O5))/SUM(HMP(D2:O2))

       

       

      Thanks,

      Sandeep

      • some_bih's avatar
        some_bih
        Icon for Community Champion rankCommunity Champion

        Hi Sandeep_PowerBI if possible provide data not as picture so I can use it for testing measure to get your expected output

  • some_bih's avatar
    some_bih
    Icon for Community Champion rankCommunity Champion

    Hi Sandeep_PowerBI  I organized your table as shown on first picture below, new calculate column

    Product = ROUND(Sheet24[Amount]*Sheet24[Weight],2)

    and created 3 Measures below. On last picture there are results. I hope this help.

    Amount_Line = SUM(Sheet24[Amount])
    Sum Product = SUM(Sheet24[Product])
    Weighted Avg =
        DIVIDE([Sum Product], [Amount_Line])
    Adjust Sheet24 for your table name
     
     

    My Excel from your data

     

     

     

     

    • Sandeep_PowerBI's avatar
      Sandeep_PowerBI
      Frequent Visitor

      Hi some_bih 

      Thanks for providing solution but in my data, I dont have weight value columns f... Only 2 categories HMP and ABC values...

      How did you calc weight (column F)