Forum Discussion

kolson256's avatar
kolson256
New Member
9 years ago
Solved

Dynamic Column Calculation Based on Multiple Slicers

I have a table of sales opportunities, and I want to create a column which displays the ratio of the opportunity's value compared to all active opportunities. I was able to accomplish this with the following column:

 

RATIO = Data[Amount] / CALCULATE(SUM(Data[Amount]),ALL(Data))

 

But my next step is to have this ratio be dependent on four slicers I have added: Quarter, Territory, Product Family, Opportunity Stage. When a user selects the 1st Quarter, EMEA Territory, ABC Product Family, Validated Opportunity Status, I want this column to adjust the denominator of the above calucation to only include opportunities which meet these criteria.

 

Can anyone shed any light on how I could do this? I am new to Power BI, and the filtering functions have not been very intuitive to me. Thank you for any help you can provide.

  • Hi kolson256,

     

    According to your description, using ALLSELECTED Function (DAX) should meet your needs. The formula below is for your reference.:smileyhappy:

    RATIO = SUM ( Table1[Amount] ) / CALCULATE ( SUM ( Table1[Amount] ), ALLSELECTED () )

     

    Regards

8 Replies

  • PavelR's avatar
    PavelR
    Solution Specialist

    Hi kolson256,

     

    as parry2k correctly said, ALLEXCEPT function will do what you want.

     

    Just use modified formula:

    RATIO = Data[Amount] / CALCULATE(SUM(Data[Amount]),ALLEXCEPT(Data;Data[Quarter];Data[Territory];Data[Product Family];Data[Opportunity]))

     

    Regards.

    Pavel

  • Baskar's avatar
    Baskar
    Resident Rockstar

    In this case ALLEXCEPT will help u.

     

    u have to understand the difference between ALL, ALLSELECTED, ALLEXCEPT.

     

    your calculation is almost correct dude, have one simple correction .

     

    u have to add ALLEXCEPT and apply what every column u want.

     

    thats it.

     

    cool

  • v-ljerr-msft's avatar
    v-ljerr-msft
    Microsoft Employee

    Hi kolson256,

     

    The value of a Calculated Column is computed during data refresh and uses the current row as a context; it does not depend on user interaction in the report.

     

    In this scenario, you should create a Measure instead, then show it with the Opportunities on the report. For more details about differences between Calculated Columns and Measures, please refer to this article.

     

    And the formula below to create the measure is for your reference.:smileyhappy:

    RATIO =
    SUM ( Data[Amount] )
        / CALCULATE (
            SUM ( Data[Amount] ),
            ALLEXCEPT (
                Data,
                Data[Quarter],
                Data[Territory],
                Data[Product Family],
                Data[Opportunity Stage]
            )
        )

     

    Regards

    • kolson256's avatar
      kolson256
      New Member

      Thank you everyone, using ALLEXCEPT does seem to have put me on the right track.

       

      v-ljerr-msft, the problem I still run into using your formula is it always calculates the ratio for each opportunity based on other opportunities which share all 4 attributes (Quarter, Territory, Product Family, Opportunity Stage). What I would like to have in the denominator is every opportunity which matches the user's current selections in the slicers.

       

      For instance, if the user has selected 1st Quarter, EMEA Territory, ABC Family, then my table will show all opportunities of all stages. I would like the ratio to then show the Amount / SUM(All Opportunities currently displayed in the table).  For instance I would like the table to look like Table 1 if I haven't made a selection in the Opportunity Stage slicer, but look like Table 2 if I have selected the Identify Stage.

       

      Table 1

      QuarterTerritoryFamilyStageAmountRatio
      1EMEAABCIdentify10010%
      1EMEAABCIdentify50050%
      1EMEAABCClosed / Won40040%
      Total   1000100%

       

      Table 2

      QuarterTerritoryFamilyStageAmountRatio
      1EMEAABCIdentify10017%
      1EMEAABCIdentify50083%
      Total   600100%
      • v-ljerr-msft's avatar
        v-ljerr-msft
        Microsoft Employee

        Hi kolson256,

         

        According to your description, using ALLSELECTED Function (DAX) should meet your needs. The formula below is for your reference.:smileyhappy:

        RATIO = SUM ( Table1[Amount] ) / CALCULATE ( SUM ( Table1[Amount] ), ALLSELECTED () )

         

        Regards

    • seena's avatar
      seena
      Frequent Visitor

      Is it possible to add additional filter to this formula which can filter the above data for TOPN customers also. I want it done dynamically.Cannot use the visual filter.