Forum Discussion

BartvDonkelaar's avatar
BartvDonkelaar
Frequent Visitor
3 years ago
Solved

Measure combining filter and group by (or similar function)

Hello,

 

I have a table containing the following columns:

- datetime

- ID

- eventname

- delta time between datetime and now (calculated column in PowerQuery)

 

Example:

datetimeIDeventnameDaysAgo
13-7-2022 07:211234Incomplete1117
13-7-2022 07:211234Incomplete1117
13-7-2022 07:211234Incomplete1117
13-7-2022 07:211234Incomplete1117
15-7-2022 07:211234Incomplete1115
16-7-2022 07:211234Incomplete1114
17-7-2022 07:211234Incomplete1113
4-8-2022 07:211234Incomplete195
4-8-2022 14:211234Incomplete195
5-8-2022 07:211234Incomplete194
6-8-2022 07:211234Incomplete193
7-8-2022 07:211234Incomplete192
20-9-2022 07:211234Incomplete148
14-7-2022 07:211235Incomplete1116
14-7-2022 07:211235Incomplete1116
14-7-2022 07:211235Incomplete1116
14-7-2022 07:211235Incomplete1116
10-7-2022 07:214923Incomplete2120
10-7-2022 07:214925Incomplete2120
11-7-2022 07:214925Incomplete1119
11-7-2022 07:214925Incomplete1119
12-7-2022 07:215825Incomplete1118
12-7-2022 07:215825Incomplete1118
12-7-2022 07:215925Incomplete1118
12-7-2022 07:215925Incomplete1118
1-7-2022 05:095947Slow2129
1-7-2022 03:587923Slow1129
1-7-2022 04:027923Incomplete1129
1-7-2022 04:417923Slow1129
1-7-2022 04:417923Incomplete1129
1-7-2022 12:257923Slow1129
1-7-2022 13:487923Incomplete1129
1-7-2022 13:487923Slow1129
1-7-2022 13:487923Incomplete1129
1-7-2022 23:487923Incomplete1128
2-7-2022 01:227923Slow1128
8-7-2022 03:597923Slow1122
8-7-2022 13:307923Slow1122
8-7-2022 13:367923Incomplete1122
10-7-2022 07:227923Slow1120
10-7-2022 08:087923Incomplete1120
10-7-2022 18:517923Slow1120
10-7-2022 20:307923Incomplete1119

 

When creating a table visual in PowerBI I can create a table like the following:

IDIncomplete1
123413

 

Here I applied the following filters:

- DaysAgo >= 120

- Event = "Incomplete1"

- Count of events with same ID >= 10

 

What I want to accomplish is to perform these filters in a measure. I have searched for the correct funtions, but cannot figure it out. Using 'Filter' I can filter on 'DaysAgo' and on the name of 'Event'. What I cannot get working is to group on ID and show only the ID's that occur 10 or more times.

 

Could someone help me out?

 

Kind regards,

 

Bart

  • BartvDonkelaar's avatar
    BartvDonkelaar
    3 years ago

    Hi Ashish_Mathur ,

     

    When I try this measure, I get an error when entering the FilterExpression. Here 

    [DaysAgo]>=120&&[Event]="Incomplete1"&&[count]>=10

    Is not recognized. The message 'Cannot find name ...' appears.

     

    COUNTROWS(
        FILTER(
            VALUES(
                table[ID]
            ),
            table[DaysAgo] <=120 &&
            table[eventname]="Incomplete1" &&
            COUNTROWS(
                table
            ) >= 10
        )
    )

    I think this is because the function 'VALUES' within the filter only relates to the [ID] column of the table, so this is the only table that is recognized to use in the FilterExpression.

     

    What I tried myself is the following:

    1. Filtering for DaysAgo and eventname is succesful.

    2. Grouping by ID (using SUMMARIZE or SUMMARIZECOLUMNS) is also succesfull, only when I start with this step the DaysAgo information is lost because of the grouping

    3. When applying the filter first, I cannot seem to refer to the newly generated filtered table.

     

    This got me thinking.. and instead of generating a measure for the filters I generated a new table. Here I applied the same logic as in the measure, only resulting in a table. This table as turned out could be used in the SUMMARIZECOLUMNS function. So now I have my column with filters and grouping! 🙂

     

    Final filter table:

    _Incompmlete1Filter = 
    FILTER(
        table,
        table[eventname] = "Incompmlete1" &&
        table[DaysAgo] <= 120
    )

     Final count table:

    _Incomplete1Count = 
    SUMMARIZECOLUMNS(
        _Incompmlete1Filter[ID],
        _Incompmlete1Filter[eventname],
        "Count",
        COUNT(
            _Incompmlete1Filter[eventname]
        )
    )

     

    Thanks for thinking along!

     

    Kind regards,

     

    Bart

7 Replies

    • BartvDonkelaar's avatar
      BartvDonkelaar
      Frequent Visitor

      Hi Greg_Deckler ,

       

      Thank you for your reply!

       

      Your solution does not however incorporate the ID.

       

      I am only interested in a case when for any individual ID the count is 10 or higher. So 10 or more times 1234 for example. In your example you sum over the total count, which does not use ID.

       

      Kind regards,

       

      Bart

  • Hi,

    At the ID level, how does one have to calculate the Days ago?  Do we have to add the 13 individual entries (after filtering for incomplete1) in the days ago column of ID 1234 or do we have to add the 10 individual unique entries (after filtering for incomplete1) in the days ago column of ID 1234?  Please clarify.

    • BartvDonkelaar's avatar
      BartvDonkelaar
      Frequent Visitor

      Hi Ashish_Mathur ,


      Thank you for your reply!

       

      I'd like to add all entries for the ID's that meet the filter criteria.

      I see that my example data is incomplete, as there should be seconds information in the datetime field. That addition makes all entries unique.

       

      Would that answer your question?

       

      Kind regards,

       

      Bart

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

        Hi,

        Does this measure work?

        Count = countrows(Data)
        Measure = COUNTROWS(FILTER(VALUES(Data[ID]),[DaysAgo]>=120&&[Event]="Incomplete1"&&[count]>=10))

        Hope this helps.