Forum Discussion

Leigh_123's avatar
Leigh_123
Frequent Visitor
3 years ago
Solved

SUMX with Distinct count on different column

Hi all,

 

I have calculation that i have created from online research that counts string column ('Query1'[Business(es) Area]) and filters by a predefined table 'Business area filter':

 

I want to be able to have a distinct count of the SUMX but based on a different column in 'Query1', is this something that is possible?

 

current dax below

 

 

 

 

Business area =
VAR __SearchTerms =
    ADDCOLUMNS (
        'Business area filter',
        "Count",
            COUNTROWS (
                FILTER (
                    'Query1',
                    FIND ( 'Business area filter'[Business Area reference],'Query1'[Business(es) Area],, 0 ) > 0
                )
            )
    )
RETURN
    SUMX ( __SearchTerms, [Count] )

 

 

 

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Leigh_123 ,

    Please have a try.

    Business area =
    VAR __SearchTerms =
        ADDCOLUMNS (
            'Business area filter',
            "Count",
                COUNTROWS (
                    FILTER (
                        'Query1',
                        FIND ( 'Business area filter'[Business Area reference],'Query1'[Your column name],, 0 ) > 0
                    )
                )
        )
    RETURN
        SUMX ( DISTINCT(__SearchTerms, 'Query1'[Your column name]), [Count] )

     

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

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

     

     

4 Replies

    • Leigh_123's avatar
      Leigh_123
      Frequent Visitor
      IDBusiness AreaCountry
      1Tax; ConsultingKorea
      2TaxFrance
      3AuditUK
      4AuditIreland
      5Audit; Tax; ConsultingAustralia
      6TaxChina
      7Audit; TaxGermany
      8ConsultingZimbabwe
      9Consulting; TaxSouth Africa
      10Consulting; TaxUS
      11AuditSwitzerland
      12AuditSwitzerland
      13Financial AdvisoryIndia
      14Risk AdvisoryJapan
      15Audit; TaxGermany
      16Risk AdvisorySpain
      17Financial Advisory; AuditNorway
      18Audit; TaxSpain
      19Enabling AreaEgypt
      20Enabling AreaEgypt
      21Audit; TaxBelgium
      22TaxGreece
      23TaxItaly
      24Conulting; Tax; AuditTurkey
      25Audit; Enabling AreaPortugal
      26AuditLatvia
      27Audit; TaxLithuania
      28Audit; Tax; Consulting; Risk AdvisoryGeorgia

      29

      Financial Advisory; Audit; TaxBarbados

       

      Providing the attached sample data. Escentially i need a distint count of "Business Area" based on "Country". I can do this with individual dax for each bsiness area:

       

      count (A&A) = 
      Calculate(
          DISTINCTCOUNT('Dummy data'[Country]),
          CONTAINSSTRING('Dummy data'[Business Area],"Audit"))

       

      However if i want to add this to a bar chart i get a mess:

      I am looking to achieve the above in the format below:

      I achieved this with the folowing Dax:

       

      Business area percentage = 
      VAR __SearchTerms =
          ADDCOLUMNS (
              'Business area filter',
              "Count",
                  COUNTROWS (
                      FILTER (
                          'Dummy data',
                          FIND ( 'Business Area Filter'[Business Area reference],'Dummy data'[Business Area],, 0 ) > 0
                      )
                  )
          )
      RETURN
          SUMX ( __SearchTerms, [Count] )

       

      Is there any way to edit this to count distinct? Apologies, i am unable to provide pbix.

       

      Thank you in advance

      • lbendlin's avatar
        lbendlin
        Icon for Super User rankSuper User

        I would recommend you solve that issue in Power Query to bring your source data into a usable format.  Then the visuals will work automatically.

         

        Note you have a data quality issue with "Conulting".

        See attached

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Leigh_123 ,

    Please have a try.

    Business area =
    VAR __SearchTerms =
        ADDCOLUMNS (
            'Business area filter',
            "Count",
                COUNTROWS (
                    FILTER (
                        'Query1',
                        FIND ( 'Business area filter'[Business Area reference],'Query1'[Your column name],, 0 ) > 0
                    )
                )
        )
    RETURN
        SUMX ( DISTINCT(__SearchTerms, 'Query1'[Your column name]), [Count] )

     

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

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