Forum Discussion
Need Help Splitting Dealers "Other" Values by same dealer Retail SG Code in Power BI
Hello everyone,
i have a dadaset in Power BI that includes sales data for different dealers, categorized by Retail and Other SG Codes. i need assistance in "Other" SGs value for each dealer and splitting them based on same dealer Retail SG Codes.
objective:
I want to achieve the following:
- For each dealer (Parent Customer) with multiple Retail SG codes, I need to add the corresponding "Other" values split equally among those Retail SG codes.
- If a dealer has three Retail SG codes, the total "Other" value should be divided by three and added to each of the Retail rows.
- The final result should show the actual Retail value plus the split "Other" value in the same row.
- For instance, if Dealer 100014 has:
- Retail SG Codes: 12 (Value = 5), 23 (Value = 5)
- Other Values: P11 (Value = 4), F10 (Value = 10)
The total "Other" value is 4 + 10 = 14. Since there are two Retail SG codes, each Retail row should receive 14 / 2 = 7.
dataset example
| Parent Customer | SG code | SG type | Month -Year | Product Code | Zone | Value |
| 100014 | 12 | Retail | Apr-24 | 12345 | Central | 5 |
| 100014 | 23 | Retail | Apr-24 | 12356 | Central | 5 |
| 100014 | P11 | Other | Apr-24 | 12367 | Central | 4 |
| 100014 | F10 | Other | Apr-24 | 12354 | Central | 10 |
| 100112 | 12 | Retail | Apr-24 | 12345 | Central | 8 |
| 100114 | 23 | Retail | Apr-24 | 12356 | Central | 20 |
| 100116 | O21 | Other | Apr-24 | 12389 | Central | 17 |
| 100153 | 2 | Retail | May-24 | 12354 | Central | 9 |
| 100153 | O21 | Other | May-24 | 12367 | Central | 13 |
| 100152 | 6 | Retail | May-24 | 12378 | Central | 18 |
| 100152 | 5 | Retail | May-24 | 12345 | Central | 16 |
| 100152 | U7 | Other | May-24 | 12345 | Central | 27 |
| 100152 | 7 | Retail | May-24 | 12356 | Central | 26 |
| 100153 | 2 | Retail | Apr-24 | 12389 | Central | 15 |
| 100153 | O21 | Other | Apr-24 | 12354 | Central | 17 |
| 100152 | 6 | Retail | Apr-24 | 12367 | Central | 4 |
| 100152 | U7 | Other | Apr-24 | 12345 | Central | 7 |
| 100152 | 7 | Retail | Apr-24 | 12356 | Central | 19 |
| 100014 | 12 | Retail | Jun-24 | 12367 | Central | 10 |
| 100014 | 23 | Retail | Jun-24 | 12354 | Central | 4 |
| 100014 | P11 | Other | Jun-24 | 12354 | Central | 15 |
| 100014 | F10 | Other | Jun-24 | 12367 | Central | 32 |
- How can I implement this logic in Power BI?
- What DAX formulas or transformations should I use to achieve this?
hi dhanurjaya ,
not sure if i fully get you, you can write a calculated column like:
column = VAR _splitBy= COUNTROWS( CALCULATETABLE( VALUES(data[SG code]), ALLEXCEPT(data, data[Parent Customer], data[Month -Year]), data[SG Type]<>"Other" ) ) VAR _othervalue = CALCULATE( SUM(data[value]), ALLEXCEPT(data, data[Parent Customer], data[Month -Year]), data[SG Type]="Other" ) VAR _splitvalue = DIVIDE(_othervalue, _splitBy) VAR _result = data[value] + _splitvalue RETURN _resultit worked like:
If the filter context could be elaborated, a measure could be written with similar logic.
Hi dhanurjaya, You can try the following steps to implement this logic in Power BI.
Step 1: Create a Calculated Column for the "Other" Values by Dealer.- Go to Modeling > New Column and create a column to calculate the total "Other" value for each dealer.
Total_Other_By_Dealer =
CALCULATE(
SUM('Table'[Value]),
'Table'[SG type] = "Other",
ALLEXCEPT('Table', 'Table'[Parent Customer], 'Table'[Month -Year])
) - This will calculate the total "Other" value for each dealer and month.
Step 2: Count the Number of Retail SG Codes per Dealer
- Create another calculated column to count the number of "Retail" SG codes for each dealer.
Retail_SG_Count =
CALCULATE(
DISTINCTCOUNT('Table'[SG code]),
'Table'[SG type] = "Retail",
ALLEXCEPT('Table', 'Table'[Parent Customer], 'Table'[Month -Year])
)
Step 3: Calculate the Split "Other" Value per Retail Row
- Create a new calculated column to calculate the split "Other" value for each Retail SG row.
Split_Other_Value =
IF(
'Table'[SG type] = "Retail",
DIVIDE('Table'[Total_Other_By_Dealer], 'Table'[Retail_SG_Count], 0),
BLANK()
) - This divides the total "Other" value by the number of "Retail" SG codes for each dealer.
Step 4: Calculate the Final Value (Retail + Split Other)
- Create another calculated column to calculate the final value for the Retail SG rows:
Final_Value =
IF(
'Table'[SG type] = "Retail",
'Table'[Value] + 'Table'[Split_Other_Value],
'Table'[Value]
) - Step 5: Create a Visual or Table to Display the Final Result
Please let me know if you need further adjustments or explanations!
If I have resolved your question, please consider marking my post as a solution. Thank you!- Go to Modeling > New Column and create a column to calculate the total "Other" value for each dealer.
Hi dhanurjaya ,
not sure if i really get you, try to plot a measure like:
measure = VAR _splitBy= COUNTROWS( CALCULATETABLE( VALUES(data[SG code]), ALLEXCEPT(data, data[Parent Customer], data[Month -Year]), data[SG Type]<>"Other" ) ) VAR _othervalue = CALCULATE( SUM(data[value]), ALLEXCEPT(data, data[Parent Customer], data[Month -Year]), data[SG Type]="Other" ) VAR _splitvalue = DIVIDE(_othervalue, _splitBy) VAR _result = SUM(data[value]) + _splitvalue RETURN IF(MAX(data[SG type]) <>"Other", _result)it worked like:
hi,
it's fine but not final result, i deen below
SG code SG type Actual Value Sum of Split value Sum of Final Value 2 Retail 24 15 39 5 Retail 16 27 43 6 Retail 22 17 39 7 Retail 45 17 62 12 Retail 23 30.5 53.5 23 Retail 29 30.5 59.5 F10 Other 42 0 42 O21 Other 47 0 47 P11 Other 19 0 19 U7 Other 34 0 34 Grand Total 301 137 438
when logic calculate at dealer SG level but i need when i see SG level total then its only sum final value not calculate logic (logic already calculate at dealer level in internal).
and one think if i select filter any by product/month/year etc. anythink its should be calculate as per selection value.
and when i count retail SG, remove filter from calender.
- Anonymous1 year ago
Hi dhanurjaya
Sorry for the late reply, please try this:
Here I create a measure to calculate the Split:
Split = VAR _currentCustomer = VALUES ( 'Table'[Parent Customer] ) VAR _countdate = DISTINCTCOUNT ( 'Table'[Month -Year] ) VAR _currentDate = MAX ( 'Table'[Month -Year] ) RETURN IF ( SELECTEDVALUE ( 'Table'[SG type] ) = "Other", 0, IF ( _countdate = 1, SUMX ( SUMMARIZE ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[SG type] = "Other" && 'Table'[Parent Customer] IN _currentCustomer && 'Table'[Month -Year] = _currentDate ), 'Table'[Parent Customer], "_AVG", CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Parent Customer] = EARLIER ( 'Table'[Parent Customer] ) ) ) ), [_AVG] ), IF ( _countdate <> 1, AVERAGEX ( SUMMARIZE ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[SG type] = "Other" && 'Table'[Parent Customer] IN _currentCustomer ), 'Table'[SG code], 'Table'[Parent Customer], "_AVG", ( CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Parent Customer] = EARLIER ( 'Table'[Parent Customer] ) ) ) / COUNTROWS ( SUMMARIZE ( FILTER ( ALLSELECTED ( 'Table' ), 'Table'[SG type] = "Other" && 'Table'[Parent Customer] IN _currentCustomer ), [Parent Customer], 'Table'[Month -Year] ) ) ) ), [_AVG] ) ) ) )The result:
Then add a measure:
Sum of Final Value = SUM('Table'[Value])+[Split]The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
10 Replies
- ryan_mayu
Super User
what's the expected output based on the sample data you provided?
could you pls add it into the sample data?
- FreemanZ
Super User
hi dhanurjaya ,
not sure if i fully get you, you can write a calculated column like:
column = VAR _splitBy= COUNTROWS( CALCULATETABLE( VALUES(data[SG code]), ALLEXCEPT(data, data[Parent Customer], data[Month -Year]), data[SG Type]<>"Other" ) ) VAR _othervalue = CALCULATE( SUM(data[value]), ALLEXCEPT(data, data[Parent Customer], data[Month -Year]), data[SG Type]="Other" ) VAR _splitvalue = DIVIDE(_othervalue, _splitBy) VAR _result = data[value] + _splitvalue RETURN _resultit worked like:
If the filter context could be elaborated, a measure could be written with similar logic.
- dhanurjayaFrequent Visitor
objective:
I want to achieve the following:
- For each dealer (Parent Customer) with multiple Retail SG codes, I need to add the corresponding "Other" values split equally among those Retail SG codes. It's should dynamic if i select some product/Period or etc. then it will calculate selected products/period or etc. value not for total value.
- If a dealer has three Retail SG codes for all period (removefilter from calender month/year etc.), the total "Other" value should be divided by three and added to each of the Retail rows.
- The final result should show the actual Retail value plus the split "Other" value in the same row. my data is larg data base so please make dax as per logic work dynamic. i think calculate column will make time to show result.thanks
- AnonymousNot applicable
Hi dhanurjaya
Please try this:
Here's the sample data:
Table:
Then add a measure:
MEASURE = VAR _currentCustomer = SELECTEDVALUE ( 'Table'[Parent Customer] ) VAR _totalOther = CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Parent Customer] = _currentCustomer && 'Table'[SG type] = "Other" ) ) VAR _numRetail = CALCULATE ( COUNT ( 'Table'[Parent Customer] ), FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Parent Customer] = _currentCustomer && 'Table'[SG type] = "Retail" ) ) RETURN IF ( SELECTEDVALUE ( 'Table'[SG type] ) = "Retail", SELECTEDVALUE ( 'Table'[SG code] ) + ( _totalOther / _numRetail ) )The result is as follow:
Best Regards
Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- grazitti_sapna
Super User
Hi dhanurjaya, You can try the following steps to implement this logic in Power BI.
Step 1: Create a Calculated Column for the "Other" Values by Dealer.- Go to Modeling > New Column and create a column to calculate the total "Other" value for each dealer.
Total_Other_By_Dealer =
CALCULATE(
SUM('Table'[Value]),
'Table'[SG type] = "Other",
ALLEXCEPT('Table', 'Table'[Parent Customer], 'Table'[Month -Year])
) - This will calculate the total "Other" value for each dealer and month.
Step 2: Count the Number of Retail SG Codes per Dealer
- Create another calculated column to count the number of "Retail" SG codes for each dealer.
Retail_SG_Count =
CALCULATE(
DISTINCTCOUNT('Table'[SG code]),
'Table'[SG type] = "Retail",
ALLEXCEPT('Table', 'Table'[Parent Customer], 'Table'[Month -Year])
)
Step 3: Calculate the Split "Other" Value per Retail Row
- Create a new calculated column to calculate the split "Other" value for each Retail SG row.
Split_Other_Value =
IF(
'Table'[SG type] = "Retail",
DIVIDE('Table'[Total_Other_By_Dealer], 'Table'[Retail_SG_Count], 0),
BLANK()
) - This divides the total "Other" value by the number of "Retail" SG codes for each dealer.
Step 4: Calculate the Final Value (Retail + Split Other)
- Create another calculated column to calculate the final value for the Retail SG rows:
Final_Value =
IF(
'Table'[SG type] = "Retail",
'Table'[Value] + 'Table'[Split_Other_Value],
'Table'[Value]
) - Step 5: Create a Visual or Table to Display the Final Result
Please let me know if you need further adjustments or explanations!
If I have resolved your question, please consider marking my post as a solution. Thank you!- dhanurjayaFrequent Visitor
SG code SG type Actual Value Sum of Split value Sum of Final Value 2 Retail 24 15 39 5 Retail 16 27 43 6 Retail 22 17 39 7 Retail 45 17 62 12 Retail 23 30.5 53.5 23 Retail 29 30.5 59.5 F10 Other 42 0 42 O21 Other 47 0 47 P11 Other 19 0 19 U7 Other 34 0 34 Grand Total 301 137 438 need this result and it's required at Measuer not calculate column.
- Go to Modeling > New Column and create a column to calculate the total "Other" value for each dealer.