Forum Discussion

sheap069's avatar
sheap069
Helper III
5 years ago
Solved

Get Values and Counts in Table

Hello,

 

I have a data set with Applications and Groups, and the data is related by the Group ID with the respective Application IDs. Application IDs have cities. 

 

Application City

1Delhi
2Delhi
3Delhi
4Delhi
5Delhi
6Delhi
7Delhi
8Delhi
9Delhi
10Delhi
11Delhi
12Mumbai
13Mumbai
14Mumbai
15Mumbai
16Mumbai
17Mumbai
18Mumbai
19Mumbai

 

ApplicationGroup
11
21
31
41
51
61
71
81
91
101
111
121
131
141
151
161
171
181
191

 

I want to display a table with one Group ID per row, with all the cities and their count in one single cell.

 

Group IDCity

1Delhi (11), Mumbai(8)

 

I've attached sample data and the desired output in the file here

 

Thank you

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi sheap069 

     

    You want a Table visual to display it? So it is a measure

     

    Result = 
    VAR T1 = GROUPBY(CityTable,CityTable[City],"COUNT",COUNTX(CURRENTGROUP(),[City]))
    VAR T2 = ADDCOLUMNS(T1,"TEST",[City]&" ("&[COUNT]&")")
    RETURN
    CONCATENATEX(T2,[TEST],", ")

     

7 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi sheap069 

     

    You want a Table visual to display it? So it is a measure

     

    Result = 
    VAR T1 = GROUPBY(CityTable,CityTable[City],"COUNT",COUNTX(CURRENTGROUP(),[City]))
    VAR T2 = ADDCOLUMNS(T1,"TEST",[City]&" ("&[COUNT]&")")
    RETURN
    CONCATENATEX(T2,[TEST],", ")

     

  • Hello Anonymous 

    As a follow up to this I have some Applications with a large number of cities. Is it possible to only display the three with the highest counts?

    Thank you

    • sheap069's avatar
      sheap069
      Helper III

      Hello Anonymous or anyone,

      I would like to display just the top three cities that have the highest counts. Is this possible to do?

      Another thing I would like to do is display the cities in order by the highest counts to the smallest.

      Thank you

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi sheap069 

         

        Sorry, missed your message...modify the T2 a little bit

        Result = 
        VAR T1 = GROUPBY(CityTable,CityTable[City],"COUNT",COUNTX(CURRENTGROUP(),[City]))
        VAR T2 =TOPN(3, ADDCOLUMNS(T1,"TEST",[City]&" ("&[COUNT]&")"),[TEST],ASC)
        RETURN
        CONCATENATEX(T2,[TEST],", ")