Forum Discussion

dhanurjaya's avatar
dhanurjaya
Frequent Visitor
1 year ago
Solved

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:

  1. 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.
  2. 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.
  3. The final result should show the actual Retail value plus the split "Other" value in the same row.                       
  4. 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 CustomerSG codeSG typeMonth -YearProduct CodeZoneValue
10001412RetailApr-2412345Central5
10001423RetailApr-2412356Central5
100014P11OtherApr-2412367Central4
100014F10OtherApr-2412354Central10
10011212RetailApr-2412345Central8
10011423RetailApr-2412356Central20
100116O21OtherApr-2412389Central17
1001532RetailMay-2412354Central9
100153O21OtherMay-2412367Central13
1001526RetailMay-2412378Central18
1001525RetailMay-2412345Central16
100152U7OtherMay-2412345Central27
1001527RetailMay-2412356Central26
1001532RetailApr-2412389Central15
100153O21OtherApr-2412354Central17
1001526RetailApr-2412367Central4
100152U7OtherApr-2412345Central7
1001527RetailApr-2412356Central19
10001412RetailJun-2412367Central10
10001423RetailJun-2412354Central4
100014P11OtherJun-2412354Central15
100014F10OtherJun-2412367Central32

 

  • 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 _result

     

    it 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!

     

  • FreemanZ's avatar
    FreemanZ
    1 year ago

    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 codeSG typeActual ValueSum of Split valueSum of Final Value
    2Retail241539
    5Retail162743
    6Retail221739
    7Retail451762
    12Retail2330.553.5
    23Retail2930.559.5
    F10Other42042
    O21Other47047
    P11Other19019
    U7Other34034
    Grand Total 301137

    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.

  • Anonymous's avatar
    Anonymous
    1 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

  • what's the expected output based on the sample data you provided?

     

    could you pls add it into the sample data?

  • 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 _result

     

    it worked like:

     

    If the filter context could be elaborated, a measure could be written with similar logic.

    • dhanurjaya's avatar
      dhanurjaya
      Frequent Visitor

      objective:

      I want to achieve the following:

      1. 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. 
      2. 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.
      3. 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
      • Anonymous's avatar
        Anonymous
        Not 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.

  • 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!

     

    • dhanurjaya's avatar
      dhanurjaya
      Frequent Visitor
      SG codeSG typeActual ValueSum of Split valueSum of Final Value
      2Retail241539
      5Retail162743
      6Retail221739
      7Retail451762
      12Retail2330.553.5
      23Retail2930.559.5
      F10Other42042
      O21Other47047
      P11Other19019
      U7Other34034
      Grand Total 301137438

       

      need this result and it's required at Measuer not calculate column.