Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Add new filter outside ALLEXCEPT

Hi, 

 

I am trying to calculate a 'share of trade' metric where the 'Total Market Sales' exists within my table. My example table looks like this:

I want to determine the following: 
Shop A's share of Total Market Sales for Category A. 

I currently have visual filters on the Category, Market, Time and State (I have another table called 'time type' that categorises FY or QTR).

 

I have tried the following

Share of Trade = DIVIDE(SUM(DF[Sales]),CALCULATE(SUM(DF[Sales]),ALLEXCEPT(DF,DF[STATE],DF[Time],DF[Time_Type])&&DF[Market] = "Total Market"),0) . 
 
But this gives me no values. 
 
Any ideas? 
  • Hi, Anonymous 

    According to your description and sample data, I can roughly understand your requirement, I think you can try this measure:

     

    Share of Trade =
    VAR _TotalMarketSales =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                [Category] = MAX ( 'Table'[Category] )
                    && [Market] = "Total Market"
            )
        )
    RETURN
    DIVIDE ( SUM ( 'Table'[Sales] ), _TotalMarketSales )

     

     

    You can set the measure format to "Percentage" like this:

     

    Then you can create a table chart and place and set the visual like this to get your expected output:

     

    And you can get what you want.

    You can download my test pbix file below

     

    If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

    How to Get Your Question Answered Quickly 

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Anonymous , Try like

     

    Share of Trade = DIVIDE(SUM(DF[Sales]),CALCULATE(SUM(DF[Sales]),Filter(allselected(DF),DF[STATE] = max(DF[STATE]) && DF[Time] = max(DF[Time]) && DF[Time_Type] = max(DF[Time_Type]) && DF[Market] = "Total Market")),0)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, 

       

      This still delivers 0.00% for all values 

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

    Hi, Anonymous 

    According to your description and sample data, I can roughly understand your requirement, I think you can try this measure:

     

    Share of Trade =
    VAR _TotalMarketSales =
        CALCULATE (
            SUM ( 'Table'[Sales] ),
            FILTER (
                ALL ( 'Table' ),
                [Category] = MAX ( 'Table'[Category] )
                    && [Market] = "Total Market"
            )
        )
    RETURN
    DIVIDE ( SUM ( 'Table'[Sales] ), _TotalMarketSales )

     

     

    You can set the measure format to "Percentage" like this:

     

    Then you can create a table chart and place and set the visual like this to get your expected output:

     

    And you can get what you want.

    You can download my test pbix file below

     

    If this result is not what you want, you can post some sample data(without sensitive data) and your expected result.

    How to Get Your Question Answered Quickly 

    Thank you very much!

     

    Best Regards,

    Community Support Team _Robert Qin

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.