Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Pivot on Multiple Dimensions and Values

I have a sales table with the following columns:

 

* Date

* Product ID

* Sales Value

* Profit

 

Because this comes off an invoicing table, there are multiple entries for each date/product ID combination. I want to combine these, so that each date and product has only one line, with the sales value and profit summed for each. How do I do this in the Power Query Editor? 

  • Anonymous first you don't need to sum these in power query, you can load raw data and just sum in your visual.  If you still want to do grouping in power query, there is group by option in the menu, pick , date to group by and use two columns to sum in the same dialog box.

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

10 Replies

  • calerof's avatar
    calerof
    Impactful Individual

    Hi Anonymous,

     

    Providing a sample of your data would help. Also, you seem to have missing some columns in your fact table. How do you know to what invoice number does each record correspond?

    F

     

    • Anonymous's avatar
      Anonymous
      Not applicable

       

      An example of the data is above. I don't want the invoice ID at all, I've already deleted it. 

       

  • Anonymous first you don't need to sum these in power query, you can load raw data and just sum in your visual.  If you still want to do grouping in power query, there is group by option in the menu, pick , date to group by and use two columns to sum in the same dialog box.

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

  • edhans's avatar
    edhans
    Community Champion

    In Power Query:

    1. Select the Date and Product ID columns
    2. On the home ribbon, select Group By
    3. In the bottom section add the Sales value, call it Sales, Sum operation, and Sales column
    4. Add an aggregation, then do Profit, Sum Operation, Profit column.

    It would look like this, but with your columns.

    It is good you are doing this. Having data at the right granularity is key to a good data model, and if you don't need the duplications of dates and product IDs, Power Query is the best way to do this.

     

    • edhans's avatar
      edhans
      Community Champion

      amitchandak what if they want to also include a count, or a daily average? Won't that make the DAX more complex? I know doing a SUM really makes no difference. 

       

      I would have thought other aggregations would be more difficult if the data was at a different granularity.

      • parry2k's avatar
        parry2k
        Super User

        edhans you this line in the signature is saying everything DAX is for Analysis. Power Query is for Data Modeling

         

        Regardless, it is sum or avg or count, I don't see any value of doing the aggregation in power query specific to this particular post.