Forum Discussion

jmorela1's avatar
jmorela1
Helper I
7 months ago
Solved

Calculation not working when slicers applied

I am trying to calculate a cost per Google form complete, but it does not calculate properly when BU or channel is selected. I have tried several different calculations/sums/measure, and cannot get the filter context to apply properly. I am having the same issue when calculating CPC and CPA.

Paid Media.pbix

 

  • MFelix's avatar
    MFelix
    7 months ago

    Hi jmorela1 ,

     

    You must add a new measure that is the cost per google for or whatever other name you want to give it and di the division of both the measures you refere:

     

    Has you can see on my image the measure for the division between both of this values gives the correct value:

     

    In the file I have shared search for the measure Cost per google form and use it on the matrix you should get the correct value.

     



23 Replies

  • Hello jmorela1,

    I examined your file and I have to say that BU and channel work fine, the point is that they show a single value so there is no difference between selecting that value or not (the only way this could make a difference, having one value, is when data are messy and you are missing a few keys, this is not the case). What I would sugges you is, on the above matter, to check whether you should have multiple vallues for those two columns while you have a single one and act accordingly.

     

    I also checked briefly the data model and I strongly suggest you to consider whether to keep or not the many to many cardinality bi-directional filter, which is usually discouraged, unless it is the only option. Many-to-many cardinality is fine (even gout a one to many would be better but it might be this is impossible in your case), but the bidirectional thing really should be avoided.

     

    If you need more support, please let us know, or if you want to explain the model thing so we can come back on the motivations you have, as a bad practice safe check

     

    Best

    If this helped, please consider giving kudos and mark as a solution

    @me in replies or I'll lose your thread

    Want to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page

    Consider voting this Power BI idea

    Francesco Bergamaschi

    MBA, M.Eng, M.Econ, Professor of BI

  • Hi jmorela1,

    Thank you for reaching out to the Microsoft Fabric Community Forum. Also, thanks to FBergamaschi, @ for his inputs on this thread.

    Has your issue been resolved? If the response provided by the community member FBergamaschi,  addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.

    if it is not resolved, Could you please upload the .pbix file to OneDrive or Google drive and share the download link here? This will allow us to open the file, reproduce the issue, and verify the model and DAX behaviour accurately.
    How to provide sample data: How to provide sample data in the Power BI Forum - Microsoft Fabric Community

    Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.

    Thank you for using the Microsoft Community Forum.

  • Hello jmorela1,

     

    This is a filter context issue. In both Power BI Desktop and Microsoft Fabric, you should define explicit measures for Cost, Clicks, Conversions, and Completes, then calculate CPC/CPA/Cost per Complete using `DIVIDE`. This ensures slicers (BU, Channel) apply consistently.

    Example Measures

    Total Cost = SUM(PaidMedia[Cost])
    Total Completes = SUM(PaidMedia[FormCompletes])
    Total Clicks = SUM(PaidMedia[Clicks])
    Total Conversions = SUM(PaidMedia[Conversions])

    Cost per Complete = DIVIDE([Total Cost], [Total Completes])
    CPC = DIVIDE([Total Cost], [Total Clicks])
    CPA = DIVIDE([Total Cost], [Total Conversions])


    Key Notes

    • Make sure BU and Channel slicers are connected via relationships.
    • If BU/Channel are in separate dimension tables, use `TREATAS` to apply slicer filters across tables.
    • If slicers still break context, wrap your measure in `CALCULATE` with `ALLSELECTED` to preserve selected filters.


    Works in Both Power BI & Fabric

    The DAX engine is the same in Power BI Desktop and Fabric semantic models, so these measures behave identically in both environments.

     

    Microsoft Documentation

     

    • Context in DAX formulas (row vs. filter context)

    `https://support.microsoft.com/en-us/office/context-in-dax-formulas-2728fae0-8309-45b6-9d32-1d600440a7ad`

     

    • CALCULATE function (DAX)

    `https://learn.microsoft.com/en-us/dax/calculate-function-dax`

     

    • ALLSELECTED function (DAX)

    `https://learn.microsoft.com/en-us/dax/allselected-function-dax`

     

    • TREATAS function (DAX)

    `https://learn.microsoft.com/en-us/dax/treatas-function-dax`

     

    • Semantic models in Microsoft Fabric

    `https://learn.microsoft.com/en-us/fabric/data-warehouse/semantic-models

    • jmorela1's avatar
      jmorela1
      Helper I
      Cost per Google Form Complete = CALCULATE(DIVIDE([Total Spend Measure],[Total form completes measure]), ALLSELECTED('OEG Consolidated'[Channel],'OEG Consolidated'[Subset BU]))
       
      Can you please advise on the above, re your direction to wrap?
      • V-yubandi-msft's avatar
        V-yubandi-msft
        Community Support

        Hi jmorela1 ,

        The DAX formula you provided is correct, but using DIVIDE inside CALCULATE with ALLSELECTED isn’t necessary for standard slicer functionality.  Channel and Subset BU slicers automatically apply the filter context if relationships are set up properly. If selecting these slicers doesn’t change the value, it’s likely an issue with the data or model, not the DAX structure.

         

        Currently, Channel and Subset BU only have one distinct value each, so selecting them won’t affect the filter context or results, which is expected behavior.

        The suggested formula is

        Cost per Google Form Complete =
        DIVIDE([Total Spend Measure], [Total form completes measure])
        

        ALLSELECTED is mainly used in specific cases, such as when handling totals across selected visuals. Using it in this context won’t address the issue and may obscure data or modeling problems.

         

        If Channel and Subset BU should have multiple values, reviewing the source data and relationships is recommended.

        Hope this helps..

         

        Regards,

        Yugandhar.

  • Hi jmorela1 

     

    Looks like your organization's policy is not letting you share the pbix file outside, or there is some sharepoint issue. (Paid Media.pbix)

    Here are a few fixes you can try - 

    Ensure there’s a proper relationship between the BU table/column and the table/column used for your CPC and CPA.
     

    • If you are using a DAX measure to calculate, you can apply the filter explicitly. For example:
    CPC = CALCULATE(
        SUM(Clicks) / SUM(Cost),
        ALLSELECTED(BU[BU])
    )

     

    • Make sure you aggregate correctly - Using an aggregator inside a CALCULATE incorrectly, for example, wrapping SUMX or AVERAGEX over a table without including BU in the row context, can ignore the slicer.

     

    • Alternatively, instead of a complicated measure, you can consider adding a custom column in the Power Query editor for your CPC and CPA calculation. And then build a relationship with the BU table in Model view.
      I would strongly suggest this approach.

     

    If this helps, please mark it as a solution so others can benefit too.

  • Hi jmorela1 ,

    If you get a chance to review my previous response, I hope it is helpful. Please take a moment to check it and let us know if you need any additional details or clarification.

     

    Thanks.

    • jmorela1's avatar
      jmorela1
      Helper I

      None of the solutions offered has fixed the cost per form complete specifically, when both a Subset BU and Channel are selected

       

      Paid Media.pbix

      • MFelix's avatar
        MFelix
        Super User

        Hi jmorela1 ,

         

        Is the calculation that you need to do the value on the column Cost per Google Form Complete?

        If this is the case you will never get the correct value since you are using measures to calculate a column and since meaures are context dependent when you add them to a column the result will be incorrect.

         

        Have you tried the measure:

        Cost per google form = DIVIDE([Total Spend Measure],[Total form completes measure])

         

        Can you explain better what is the value you want to achieve. In the file you share there is only one BU so is difficult to give the correct syntax.