Create a measure to find the sum of PromoDays for each Customer and SKU. Customer and…
- User
Create a measure to find the sum of PromoDays for each Customer and SKU. Customer and SKU are placed in table1, while Customer Code, SKU Code, and PromoDays are placed in table2. Customer corresponds to Customer Code and SKU corresponds to SKU Code. Table1 and table2 are not related. Write the DAX expression
- Assistant
To create a measure to find the sum of PromoDays for each Customer and SKU, you can follow these steps:
- Open Power BI Desktop and go to the "Modeling" tab.
- In the "Fields" pane, ensure that both table1 and table2 are visible.
- Click on the table2 to select it.
- Go to the "Table" section and click on "New Measure".
- In the formula bar, enter the following DAX expression:
codeTotal PromoDays = SUM(table2[PromoDays])- Press Enter to create the measure.
- Now, you need to create a relationship between table1 and table2 based on the Customer and SKU columns. If there is no common key between these tables, you can consider using a calculated column or Power Query to establish a relationship. This step is important to ensure accurate results in the visualization.
- Once the relationship is established, you can use the measure "Total PromoDays" in your visualizations to get the sum of PromoDays for each Customer and SKU.
Note: The measure created above will give you the total sum of PromoDays for each combination of Customer and SKU. If you want separate sums for each Customer and each SKU, you can create separate measures or use other DAX functions like CALCULATE and SUMX to achieve the desired result.
- User
Solve this problem without establishing relationships between two tables
- Assistant
If you do not want to establish relationships between the two tables, you can use the CALCULATE and SUMX functions in DAX to calculate the sum of PromoDays for each Customer and SKU.
Here's the DAX expression:
codeTotal PromoDays = CALCULATE( SUMX( VALUES(table2[Customer Code] & table2[SKU Code]), table2[PromoDays] ), ALLEXCEPT(table2, table2[Customer Code], table2[SKU Code]) )This expression calculates the sum of PromoDays by iterating over each distinct combination of Customer Code and SKU Code in table2. The SUMX function is used to iterate over the distinct combinations, while the CALCULATE function performs the sum calculation. The ALLEXCEPT function removes any existing filters on table2 except for Customer Code and SKU Code, ensuring that the sum is calculated correctly.
You can create this measure in Power BI Desktop by following the same steps mentioned earlier for creating a measure. Once created, you can use the measure "Total PromoDays" in your visualizations to view the sum of PromoDays for each Customer and SKU.
- User
No, I want the sum of PromodDays for Customer and SKU. Not all Customer and SKU from table1 are present in table2. Not all Customer Code and SKU Code are present in table1.
- Assistant
Apologies for the confusion. Based on your clarification, here's the updated DAX expression to calculate the sum of PromoDays for each Customer and SKU, considering that not all Customer and SKU combinations are present in both table1 and table2:
codeTotal PromoDays = IF( ISBLANK( SUMX( FILTER(table2, RELATED(table2[Customer Code]) = table1[Customer] && RELATED(table2[SKU Code]) = table1[SKU] ), table2[PromoDays] ) ), 0, SUMX( FILTER(table2, RELATED(table2[Customer Code]) = table1[Customer] && RELATED(table2[SKU Code]) = table1[SKU] ), table2[PromoDays] ) ) - User
No, you do not understand. See the example. Table1: Year/Month/Customer/SKU 2023/1/X/1 2023/1/X/2 2023/2/X/1 2023/2/Y/1 2023/2/Y/2
Table 2: Year/Month/Customer Code/SKU Code/PromoDays 2023/1/X/1/10 2023/1/Z/1/10 2023/2/Y/2/15
I want a measure to construct a table Year/Month/Customer/SKU/New measure 2023/1/X/1/10 2023/1/X/2/0 2023/2/X/1/0 2023/2/Y/1/0 2023/2/Y/2/15
New measure relates to table2 looking PromoDays based on values of Year, Month, Customer, SKU in table1 and Year, Month, Customer Code, and SKU Code in table2. Provide the expression
- Assistant
Apologies for the confusion earlier. Based on your updated requirements and the example provided, here's the DAX expression to calculate the "New measure" that retrieves the PromoDays from table2 based on matching criteria from table1:
code