Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BartvDonkelaar
Frequent Visitor

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

1 ACCEPTED SOLUTION

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

View solution in original post

7 REPLIES 7
Ashish_Mathur
Super User
Super User

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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

Hi,

Does this measure work?

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

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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

Since your reply has been marked as Answer, my guess is that is question is answered.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

@BartvDonkelaar With ID in your table visual, try something like:

Measure = 
  VAR __Table = FILTER('Table', [DaysAgo] >= 120 && [Event] = "Incomplete1")
  VAR __Count = COUNTROWS(__Table)
  VAR __Result = IF(__Count >= 10, 1, 0)
RETURN
  __Result

Basically a Complex Selector: The Complex Selector - Microsoft Power BI Community

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.