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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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