Forum Discussion

TA9's avatar
TA9
Frequent Visitor
3 years ago
Solved

counting occurrences

Hi,

 

I have two fields ID and outcome. Each ID can have more than one outcome and each outcome is on a separate row (example below)

 

IDOutcome
1A
1B
2C
3A
3C
4B
4C
4D

 

I would like to find out the number of occurrences of a number of outcomes

 

Example above would have following results (ID in brackets just to help explain, they will not be in the output)

 

 

Number of OutcomesNumber of Occurrences
11 (ID 2)
22 (ID 1 and 3)
31 (ID 4)

 

Can this be done with a measure or will I need to create interim tables?

 

Thanks 

  • Hi,

    I suggest ( and agree with you) having an additional table like below.

    Please check the below picture and the attached pbix file whether it suits your requirement.

     

     

     

     

    Number of Occurreces measure: =
    VAR _newtable =
        ADDCOLUMNS ( DISTINCT ( Data[ID] ), "@count", CALCULATE ( COUNTROWS ( Data ) ) )
    VAR _filtertable =
        FILTER ( _newtable, [@count] = MAX ( 'Axis'[Axis] ) )
    RETURN
        COUNTROWS ( _filtertable )
    

     

2 Replies

  • Hi,

    I suggest ( and agree with you) having an additional table like below.

    Please check the below picture and the attached pbix file whether it suits your requirement.

     

     

     

     

    Number of Occurreces measure: =
    VAR _newtable =
        ADDCOLUMNS ( DISTINCT ( Data[ID] ), "@count", CALCULATE ( COUNTROWS ( Data ) ) )
    VAR _filtertable =
        FILTER ( _newtable, [@count] = MAX ( 'Axis'[Axis] ) )
    RETURN
        COUNTROWS ( _filtertable )
    

     

    • TA9's avatar
      TA9
      Frequent Visitor

      That worked perfectly! thank you ğŸ˜€