Forum Discussion

powerbiwork's avatar
powerbiwork
Helper I
5 years ago
Solved

Calculated Column/Measure based on Filter

Hi, 

 

I needed to create a measure/column that can take a field in opportunity object from SalesForce and multiply based on a filter slicer. For example, I need to multiply opportunity services amount by Booked% below based on the filter if I select commodities and 2/5/2021. Is it possible?

 

 

Thank you so much in advance. 

 

  • Hi, powerbiwork 

    The filters works on the table visual, so there is no need to create an additional virtual table "myFilteredTable" in your measure "Division Factor".

     

    It is recommended to calculate in two steps.
    Step1: calculate the factor as below first.

    Factor =
    SWITCH (
        SELECTEDVALUE ( Opportunity[Commit_Upside__c] ),
        "Booked", SUM ( '2021 Assumptions'[Booked%] ),
        "Commit", SUM ( '2021 Assumptions'[Commit%] ),
        "Upside", SUM ( '2021 Assumptions'[Upside%] ),
        "Potential", SUM ( '2021 Assumptions'[Potebtial%] ),
        "Pipeline", SUM ( '2021 Assumptions'[Pipeline%] )
    )
    

    Step 2: Column "Opportunity'[Positive_Services_Amount__c USD])"  multiplied by factor “Factor”

     

    Value = SUM(Opportunity[ToUSD-Positive_Services_Amount])* [Division Factor]

     

     

     

    Please check my sample file for more details.

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

5 Replies

  • selimovd's avatar
    selimovd
    Most Valuable Professional

    Hey powerbiwork ,

     

    you should do that with a measure. A calculated column is always static, so you can't change that dynamically.

    Try the following measure and replace your columns accordingly:

     

     

    Division Factor =
    VAR SelectedDivision = SELECTEDVALUE( DimDivision[Division] )
    VAR SelectedDate     = SELECTEDVALUE( DimDate[Date] )
    VAR myFilteredTable  =
        CALCULATETABLE(
            MyFactTable,
            DimDate[Date] = SelectedDate,
            DimDivision[Division] = SelectedDivision
        )
    RETURN
        SUMX( myFilteredTable, MyFactTable[Booked%] * [Opportunity Services])

     

     

     

    I was assuming Opportunity Services is a measure.

     

    If you need any help please let me know.
    If I answered your question I would be happy if you could give it a thumbs up 👍!

    Best regards
    Denis

    • powerbiwork's avatar
      powerbiwork
      Helper I

      Hi selimovd 

       

      Thank you so much for your solution it really helps. However, I did run into other issues and I should have been more clear in the beginning. So the goal of the filtered table was so that I could use this formula:

       

      if ('Opportunity'[Commit_Upside__c] = "Booked", 'Opportunity'[ToUSD-Positive_Services_Amount] * sum('2021-Assumptions'[Booked%]),
      if ('Opportunity'[Commit_Upside__c] = "Commit", 'Opportunity'[ToUSD-Positive_Services_Amount] * sum('2021-Assumptions'[Commit%]),
      if ('Opportunity'[Commit_Upside__c] = "Upside", 'Opportunity'[ToUSD-Positive_Services_Amount] * sum('2021-Assumptions'[Upside%]),
      if ('Opportunity'[Commit_Upside__c] = "Potential", 'Opportunity'[ToUSD-Positive_Services_Amount] * sum('2021-Assumptions'[Potential%]),
      if ('Opportunity'[Commit_Upside__c] = "Pipeline", 'Opportunity'[ToUSD-Positive_Services_Amount] * sum('2021-Assumptions'[Pipeline%]), 0)
      ))))
       
      so if I plug in to your formula it doesn't seem to work because it requires it to be a measure to begin with?
      • selimovd's avatar
        selimovd
        Most Valuable Professional

        Hey powerbiwork ,

         

        I try to understand where the data is coming from.

        What is the table Opportunity and where is the column Commit_Upside__c? Is this another table? Is this in the same table? How would it look if you filter by division?

         

        Best regards

        Denis

  • v-easonf-msft's avatar
    v-easonf-msft
    Community Support

    Hi, powerbiwork 

    The filters works on the table visual, so there is no need to create an additional virtual table "myFilteredTable" in your measure "Division Factor".

     

    It is recommended to calculate in two steps.
    Step1: calculate the factor as below first.

    Factor =
    SWITCH (
        SELECTEDVALUE ( Opportunity[Commit_Upside__c] ),
        "Booked", SUM ( '2021 Assumptions'[Booked%] ),
        "Commit", SUM ( '2021 Assumptions'[Commit%] ),
        "Upside", SUM ( '2021 Assumptions'[Upside%] ),
        "Potential", SUM ( '2021 Assumptions'[Potebtial%] ),
        "Pipeline", SUM ( '2021 Assumptions'[Pipeline%] )
    )
    

    Step 2: Column "Opportunity'[Positive_Services_Amount__c USD])"  multiplied by factor “Factor”

     

    Value = SUM(Opportunity[ToUSD-Positive_Services_Amount])* [Division Factor]

     

     

     

    Please check my sample file for more details.

     

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.