Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Filter Costs by Region, or Update Query Data with Proper Costs Column

Hi Everyone,

 

I could use some help in figuring out how to best find the aggregate costs of goods sold based on region.

 

Say a good costs $1 in the US, $2 in Europe, and $3 in Asia. Each specific sale is a separate row in my data set, however the cost of the good is not directly mapped to the sale based on region. I have a column that states which sale the region was made, but for the cost, I have separate columns for the $1, $2, and $3(the US Cost column has $1 for every row, Europe shows $2 for every row, etc.) . Is there a way to connect the proper cost for each sale in a single column (i.e. if the sale was in Europe, it will know to make the cost column say $2)? Or, is there an M code to filter it by cost based on region?

 

Thanks!   

  • Anonymous's avatar
    Anonymous
    7 years ago

    HI Anonymous ,

    Power bi not suitable to calculate across multiple fields, I'd like to suggest you enter the query editor and use unpivot columns feature to convert these cost fields to attribute and value.

    Unpivot columns (Power Query)
    After these steps, you can simple filter on region attribute or write formula to calculate based on current category group.

    Regards,

    Xiaoxin Sheng

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Please share some sample data with expect result to help us clarify your requirement and do test to coding formula.

    Regards,

    Xiaoxin Sheng

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi v-shex,

       

      For example, I have the costs for each region placed in separate columns (EMEA = EU and APAC = AP - in the region column). Is there a way I can make a new column that assigns the appropriate cost for each row depending on the region, rather than having three separate columns? Or is there an M code that can filter it out at a later stage?

       

      Thanks!

       

      • Anonymous's avatar
        Anonymous
        Not applicable

        HI Anonymous ,

        Power bi not suitable to calculate across multiple fields, I'd like to suggest you enter the query editor and use unpivot columns feature to convert these cost fields to attribute and value.

        Unpivot columns (Power Query)
        After these steps, you can simple filter on region attribute or write formula to calculate based on current category group.

        Regards,

        Xiaoxin Sheng