Forum Discussion

jkrewpbi's avatar
jkrewpbi
Frequent Visitor
10 years ago

Generate calculated table containing rows where count of a value is greater 0 for each user

I know this is easy, but I can't see to find the right combination of steps to do what I'm trying to do.

 

I currently have TABLE_ALL that contains three columns (for example sake):  user(int) contact_method(varchar) confirmed(True or False)

 

In this table, a user might have 0, 1, 2, or 3 confirmed contact methods.

 

I need to build a calcualted table - TABLE_NO_CONFIRMED -  that contains all users that have 0 (none) confirmed contact methods.

 

I've begun chipping away by trying to simply filter on a count - but I'm missing how to roll up the count for each user. Here is my attempt that I know is incorrect, but at least it illiustrates my novice approach. Thanks for any input on how to do this:

 

(my approach which is of course not working): TABLE_NO_CONFIRMED = FILTER(‘db TABLE_A’,COUNTAX('db TABLE_A',COUNTAX('db TABLE_A','db TABLE_A'[confirmed] = TRUE())))

 

 

9 Replies

  • CahabaData's avatar
    CahabaData
    Icon for Memorable Member rankMemorable Member

    To clarify: you state

    confirmed(True or False) 

    Then: "a user might have 0, 1, 2, or 3 confirmed contact methods"

     

    so then it would be a record count? (since the field is true/false) meaning that if 0 contacts you want to count False and only false?

     

     

     

     

    • jkrewpbi's avatar
      jkrewpbi
      Frequent Visitor

      For your question "so then it would be a record count? (since the field is true/false) meaning that if 0 contacts you want to count False and only false?".

       

      Almost - I need the list of users that have False for EVERY contact_method.

       

      Another way to look at it (I've added the campaign column in this example - just for context since this table is tied to others via the campaign:

       

      TABLE_A:

      campaign  user_id       contact_method   confirmed

      X              123            email                  False

      X              123            text                    False

      X              321            email                  True

      X              321            text                    False

       

      So for my calculated table, I'm looking to get the following result:

       

      campaign  user

      X              123

       

      I felt it would be kind of odd to stick a calculated column in TABLE_A, because whle the data exists in TABLE_A to determine which users did not confirm at all, I tend to think of keeping calculated/summary data separate from non calculated.

       

       

      • CahabaData's avatar
        CahabaData
        Icon for Memorable Member rankMemorable Member

        It would be easier for me to revert to SQL logic rather than DAX for something like this.  I would:

        a. created a calculated table: TableFalse      that is just the false records

        b. created a calculated table: TableTrue      that is just the true records

        c. do an outer join on the ID field of TableFalse to TableTrue so all False records result

        .....in this resulting table some rows will have the TableTrue fields as blanks

        d. create a calculated table: NoMethod       that filters out the records with blank TableTrue fields (only 1 field is needed)

         

        this might not get you quite there - - air code and haven't completely thought thru every possible variation.....but will get you close

         

        am pretty sure I forgot to include Distinct.... you'll want 1 record per ID in each table true/false......