I have a table with columns Group, NS, Period, SKU, Payer in table1 and SB, Period, SKU,…
- User
I have a table with columns Group, NS, Period, SKU, Payer in table1 and SB, Period, SKU, Payer in table2. These two tables are connected through other tables and fields Period, SKU, Payer. I need a column to distibute SB across Group proportionally to NS for each unique combination of Period, SKU, Payer. For example, Group = 1 and NS = 10, Group = 2 and NS = 40 for Period = 20, SKU = 111, Payer = XX. Then SB = 100 for Period = 20, SKU = 111, Payer = XX will be distributed as 10/(10+40)*100 = 20 for Group = 1 and 40/(10+40)*100=80 for Group = 2. Write DAX expression for calculated column
- Assistant
To create a calculated column in table1 to distribute SB across Group proportionally to NS for each unique combination of Period, SKU, and Payer, you can use the following DAX expression:
SB Distribution = VAR TotalNS = CALCULATE(SUM(table1[NS])) RETURN table1[NS] / TotalNS * RELATED(table2[SB])This expression calculates the total NS across all groups within the unique combination of Period, SKU, and Payer. It then divides the specific NS value in table1 by the total NS and multiplies it by the corresponding SB value from table2.
Note: Replace
table1andtable2with the actual table names in your dataset. - User
Redo if two tables are not related. There are no relationships between tables
- Assistant
If there are no relationships between the two tables, you can still calculate the desired distribution of SB across Group proportionally to NS for each unique combination of Period, SKU, and Payer by using a combination of SUMX, FILTER, and CALCULATE functions in the DAX expression.
Assuming you have two tables named "table1" and "table2" without any relationships, you can use the following DAX expression to create a calculated column in "table1" that performs the distribution:
SB Distribution = VAR TotalNS = CALCULATE( SUM(table1[NS]), ALLEXCEPT(table1, table1[Period], table1[SKU], table1[Payer]) ) VAR CurrentCombination = CONCATENATE(table1[Period], table1[SKU], table1[Payer]) RETURN SUMX( FILTER( table1, CONCATENATE(table1[Period], table1[SKU], table1[Payer]) = CurrentCombination ), table1[NS] ) / TotalNS * MAXX(FILTER(table2, CONCATENATE(table2[Period], table2[SKU], table2[Payer]) = CurrentCombination), table2[SB]) - User
Do not use CONCATENATE
- Assistant
If you prefer not to use CONCATENATE, you can modify the DAX expression as follows:
SB Distribution = VAR TotalNS = CALCULATE( SUM(table1[NS]), ALLEXCEPT(table1, table1[Period], table1[SKU], table1[Payer]) ) VAR CurrentCombination = table1[Period] & "|" & table1[SKU] & "|" & table1[Payer] RETURN SUMX( FILTER( table1, table1[Period] = EARLIER(table1[Period]) && table1[SKU] = EARLIER(table1[SKU]) && table1[Payer] = EARLIER(table1[Payer]) ), table1[NS] ) / TotalNS * MAXX( FILTER( table2, table2[Period] = EARLIER(table1[Period]) && table2[SKU] = EARLIER(table1[SKU]) && table2[Payer] = EARLIER(table1[Payer]) ), table2[SB] )In this modified expression, the CurrentCombination variable is defined using the ampersand (&) operator to concatenate the values of Period, SKU, and Payer with a "|" separator.
The FILTER function is used with conditions on Period, SKU, and Payer to obtain only the rows that match the current combination of Group, NS, and Period in table1. The EARLIER function is used to refer to the values of Period, SKU, and Payer from the outer SUMX and MAXX functions.
- User
The function does not yield values for all rows in Group column
SB = VAR TotalNS = CALCULATE( SUM('16-ая плательщик+SKU'[Total NS0]), ALLEXCEPT('16-ая плательщик+SKU', '16-ая плательщик+SKU'[Period], '16-ая плательщик+SKU'[Payer Code], '16-ая плательщик+SKU'[SCU Code]) )
RETURN SUMX( FILTER( '16-ая плательщик+SKU', '16-ая плательщик+SKU'[Period] = EARLIER('16-ая плательщик+SKU'[Period]) && '16-ая плательщик+SKU'[Payer Code] = EARLIER('16-ая плательщик+SKU'[Payer Code]) && '16-ая плательщик+SKU'[SCU Code] = EARLIER('16-ая плательщик+SKU'[SCU Code]) ), '16-ая плательщик+SKU'[Total NS0] ) / TotalNS * MAXX( FILTER( 'Выгрузка FPM', 'Выгрузка FPM'[Period] = EARLIER('16-ая плательщик+SKU'[Period]) && 'Выгрузка FPM'[Code Payer] = EARLIER('16-ая плательщик+SKU'[Payer Code]) && 'Выгрузка FPM'[Code SKU] = EARLIER('16-ая плательщик+SKU'[SCU Code]) ), 'Выгрузка FPM'[Custom.Sales Bonus (Loc)] )
- Assistant
Based on the provided information, it seems that the DAX expression is correctly written. However, it's difficult to determine the cause of the issue without further details about the data and expected results.
Here are a few steps you can follow to troubleshoot the problem:
- Check if there are any filters or slicers applied to the table or report that could be affecting the visibility of certain rows.
- Verify that the Period, Payer Code, and SCU Code columns have consistent values and data types in both tables.
- Ensure that there are matching values for each unique combination of Period, Payer Code, and SCU Code in both tables.
- Double-check the source data to ensure it contains the expected values and there are no data quality issues.
- Analyze the TotalNS calculation to ensure it returns the correct value for each unique combination.
If the issue persists, it may be helpful to provide a sample of the data and expected results so that I can assist you further.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.