Forum Discussion

DataScope06's avatar
DataScope06
Helper I
3 years ago
Solved

Sum value by multiple dimensions in multiple tables

I have a data model with several tables. I need to sum the number of items ordered by product category for each customer and each year.

 

Tables listed here:

 

sales_items

OrderIDSKUQty_ordered
11232
21243
31252
41261
51272
61232

 

sales_order

OrderIDCustomerIDOrder_Date
111/1/2020
226/1/2020
331/1/2021
418/1/2021
5212/1/2021
612/1/2022

 

product

SKUProductCategory
123Hats
124Gloves
125Shirts
126Pants
127Shoes

 

date

DateYearMonth
1/1/20202020January
6/1/20202020June
1/1/20212021January
8/1/20212021August
12/1/20212021December
2/1/20222022February

 

Here is the expected output for CustomerID # 1. Note: I do not want this specific to customer #1, it needs to return this type of output for all Customer-Year-ProductCategory combinations. Customer #1 results are only shown as a brief example.

CustomerIDYearProductCategoryQtyOrdered
12020Hats2
12021Pants1
12022Hats2
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi DataScope06 ,

    I have created a simple sample, please refer to it to see if it helps you.

    Create a measure.

    Measure =
    CALCULATE (
        MAX ( sales_items[Qty_ordered] ),
        FILTER (
            ALL ( 'product' ),
            'product'[SKU] = SELECTEDVALUE ( sales_items[SKU] )
        )
    )
    

    The year table has no relationship with other tables, so we cannot output the year column.

     

    Best Regards

    Community Support Team _ Polly

     

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

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi DataScope06 ,

    Could you please provide some sample data in the tables and the desired output with the sample data?

    How to Get Your Question Answered Quickly 

     

     

    Best Regards

    Community Support Team _ Polly

     

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

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi DataScope06 ,

    You need to sum the number of items ordered by product category for each customer and each year. There are so many year, Who corresponds to which year? And there cannot create relationships among the date table and other tables.

     

    Could you also provide the desired output with the pictures like the above?

     

    Best Regards

    Community Support Team _ Polly

     

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

    • DataScope06's avatar
      DataScope06
      Helper I

      Anonymous I just edited the question to make it more specific. I also added an example output.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi DataScope06 ,

    I have created a simple sample, please refer to it to see if it helps you.

    Create a measure.

    Measure =
    CALCULATE (
        MAX ( sales_items[Qty_ordered] ),
        FILTER (
            ALL ( 'product' ),
            'product'[SKU] = SELECTEDVALUE ( sales_items[SKU] )
        )
    )
    

    The year table has no relationship with other tables, so we cannot output the year column.

     

    Best Regards

    Community Support Team _ Polly

     

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

    • DataScope06's avatar
      DataScope06
      Helper I

      Thanks for the submission, Anonymous . The year does have a relationship to other tables. The table, sales_order, has an order_date which joins to the date table. How can year then be tied in?