Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Check several rows with same ID

Hi folks,

 

I am quite new to PowerBI and currently wokring on the following topic:

 

I do have messages and message_threads, both are in one table. Messages can be either OUTBOUND (sent by company) or INBOUND (sent by customer). I now want to count the number of active threads, meaning the number of threads where at least one message was sent by the customer.

 

message-idthread-idmessage-type
11OUTBOUND
21OUTBOUND
32OUTBOUND
42INBOUND
52OUTBOUND
63OUTBOUND
73OUTBOUND
83

INBOUND

 

In this Case thread 2 and 3 are active threads (at least one message with type INBOUND). Thread 1 is not active.

 

The outcome I would expect would for example look like the following:

 

message-idthread-idmessage-typeactive
11OUTBOUNDfalse
21OUTBOUNDfalse
32OUTBOUNDtrue
42INBOUNDtrue
52OUTBOUNDtrue
63OUTBOUNDtrue
73OUTBOUNDtrue
83

INBOUND

true

 

Thanks a lot in advance 🙂

 

  • tamerj1 

     

    There's no need to use IF here since ISEMPTY is already a logical function. This is the same:

    NOT ISEMPTY(
        FILTER(
            CALCULATETABLE(
                T,
                ALLEXCEPT(
                    T,
                    T[thread-id]
                )
            ),
            T[message-type] = "INBOUND"
        )
    )

5 Replies

  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi Anonymous 

    please try

    =
    IF (
        ISEMPTY (
            FILTER (
                CALCULATETABLE ( TableName, ALLEXCEPT ( TableName, TableName[thread-id] ) ),
                TableName[message-type] = "INBOUND"
            )
        ),
        FALSE,
        TRUE
    )
    • daXtreme's avatar
      daXtreme
      Solution Sage

      tamerj1 

       

      There's no need to use IF here since ISEMPTY is already a logical function. This is the same:

      NOT ISEMPTY(
          FILTER(
              CALCULATETABLE(
                  T,
                  ALLEXCEPT(
                      T,
                      T[thread-id]
                  )
              ),
              T[message-type] = "INBOUND"
          )
      )
  • daXtreme's avatar
    daXtreme
    Solution Sage
    // Let the table be T.
    
    [# Active Threads] =
    CALCULATE(
        DISTINCTCOUNT( T[thread-id] ),
        DISTINCT( T[thread-id] ),
        T[message-type] = "inbound",
        REMOVEFILTERS( T )
    )
  • Thank a lot daXtreme tamerj1 ,

    I have to correct my initial table I posted. 

    factMessages

    Message-idThread-IDMessageAttrKey
    111
    2 2
    323
    424

     

    dimMessageAttributes

    MessageAttrKeyType...
    1OUTBOUND 
    2OUTBOUND 
    3INBOUND 
    4INBOUND