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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
FreemanZ
Super User
Super User

How to handle filter-aggregate-filter scenario?

For the table below, I am trying to get a list of Product with 0 SalesAmount in the last 3 months. 
 
Month
Product
SalesAmount
Jan
A
0
Jan
B
84
Jan
C
0
Feb
A
68
Feb
B
0
Feb
C
0
Mar
A
92
Mar
B
0
Mar
C
0
Apr
A
61
Apr
B
76
Apr
C
0

 

How could it be done?

 
(BTW, filter-aggregate-filter is my personal understanding only, anyway workable would be great. )
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @FreemanZ ,

 

Min sales:

easure = 
var minsales = CALCULATE(MIN('Table'[SalesAmount]),FILTER(ALLEXCEPT('Table','Table'[Product]),'Table'[MonthNo]>MAXX(ALLSELECTED('Table'),'Table'[MonthNo])-3))
return
IF(minsales>0,0,1)

vjaywmsft_0-1666946764454.png

Sum sales:

Measure = 
var sumsales = CALCULATE(SUM('Table'[SalesAmount]),FILTER(ALLEXCEPT('Table','Table'[Product]),'Table'[MonthNo]>MAXX(ALLSELECTED('Table'),'Table'[MonthNo])-3))
return
IF(minsales>0,0,1)

vjaywmsft_1-1666946792332.png

 

Best Regards,

Jay

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @FreemanZ ,

 

Min sales:

easure = 
var minsales = CALCULATE(MIN('Table'[SalesAmount]),FILTER(ALLEXCEPT('Table','Table'[Product]),'Table'[MonthNo]>MAXX(ALLSELECTED('Table'),'Table'[MonthNo])-3))
return
IF(minsales>0,0,1)

vjaywmsft_0-1666946764454.png

Sum sales:

Measure = 
var sumsales = CALCULATE(SUM('Table'[SalesAmount]),FILTER(ALLEXCEPT('Table','Table'[Product]),'Table'[MonthNo]>MAXX(ALLSELECTED('Table'),'Table'[MonthNo])-3))
return
IF(minsales>0,0,1)

vjaywmsft_1-1666946792332.png

 

Best Regards,

Jay

FreemanZ
Super User
Super User

This code works:

EVALUATE
VAR TABLE1 =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( 'Table', 'Table'[Product] ),
            "Amount", CALCULATE ( SUM ( 'Table'[SalesAmount] ) )
        ),
        FILTER ( 'Table', 'Table'[Month] IN { "Apr", "Mar", "Feb" } )
    )
VAR TABLE2 =
    FILTER ( TABLE1, [Amount] = 0 )
RETURN
    TABLE2
 
Previously I was obsessed why the more intuitive expression below doesn't work:
EVALUATE
VAR TABLE1= FILTER ('Table', 'Table'[Month] in {"Apr", "Mar", "Feb"})
VAR TABLE2 =
    SUMMARIZE( 'Table1', 'Table'[Product])
VAR TABLE3 =
    ADDCOLUMNS( TABLE2, "Amount", CALCULATE( SUM ('Table'[SalesAmount])))
VAR TABLE4 =
    FILTER (Table3, [Amount]=0)
RETURN Table4
 
It seems the first FILTER has no memory.
 
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

All measures are in the attached pbix file.

 

Jihwan_Kim_1-1666843498709.png

 

 

Jihwan_Kim_0-1666843482962.png

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.