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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Using GROUPBY with dynamic filter context

Hi all,

 

I'm struggling with the GROUPBY() function. I would like to group my data by ITEM and doing an average on the volume. The table is filtered by a slicer on the minimum date. It seems like the GROUPBY function is not considering the filter context as the average volume is the same with or without the date slicer.

 

Table:

ITEM | DATE | VOLUME

A; 01/01/2013; 50

A; 05/01/2013; 60

A; 05/01/2015; 70

B; 01/01/2013; 50

B; 06/02/2013; 50

B; 05/03/2015; 40

 

Here is the code I'm using.

 

=GROUPBY(
                   Table;
                   Table[ITEM];
                   "Average volume by item";
                    AVERAGEX(
                                     CURRENTGROUP();
                                      Table[Volume]
                                     )
)

I would like the GROUPBY() to group the table already filtered with the date slicer, for example Date > 01/01/2017.

I should end up with this:


ITEM | AVG VOLUME

A; 70

B; 40

 

It's not the case and it seems like GROUPBY  is ignoring the filter context.

 

What would be the right way to do it?

 

Thank you very much.

 


                                     

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

In this case, you have to use the column name only, without the table name:

SUMX( Group_Max; [Max volume] )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

View solution in original post

8 REPLIES 8
AlB
Community Champion
Community Champion

Hi @Anonymous 

You seem to be creating a calculated table. That is static and will not be affected by filter context at all. Try creating a table visual instead, with the appropriate measure

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

Anonymous
Not applicable

Hi AIB, thanks for you help.

 

Is their a function I could use in this measure instead of GROUPBY to average on the same "ITEM"?

AlB
Community Champion
Community Champion

@Anonymous 

How about you just

1. Place Table[ITEM] in the rows of a matrix visual

2. Place this simple measure in the visual

 

Measure = 
AVERAGE( Table[Volume] )

 

3. Use a slicer for the date

Wouldn't that yield what you're looking far or am I completely misunderstanding? 

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

Anonymous
Not applicable

Ok I get what you mean now but I need a table as an output. I'm doing further calculations based on this groupby table.
AlB
Community Champion
Community Champion

You can create a table within a measure that will be affected by  filter context

Measure = 

Var AuxTable_ = //Your code from earlier (GROUPBY)

RETURN

// The rest of the code using that table here  

Anonymous
Not applicable

Hello @AlB ,

 

Thanks for your reply. I'm trying to give it a try to your solution and I think that it could do the job but I'm struggling with the syntax.

 

How do you recall à created column in the GROUPBY function stocked in the variable?

 

VAR
Running_date= MAX(Calendar[date])
VAR
Filtered_table_to_date= FILTER(Table1; Table1[date]<=Running_date)
VAR
Group_Max=
GROUPBY(
Filtered_table_to_date;
Table1[Item];
"Max volume"; MAXX(CURRENTGROUP(); Table1[Volume]
RETURN

SUMX(Group_Max; Group_Max[Max volume])


How it should be written in the SUMX function?

 

Rgds,

 

 

AlB
Community Champion
Community Champion

Hi @Anonymous 

In this case, you have to use the column name only, without the table name:

SUMX( Group_Max; [Max volume] )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

Anonymous
Not applicable

Thank you so much, works perfectly!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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