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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Syndicate_Admin
Administrator
Administrator

Combined filters in DAX using AND and OR

Hello Community!

I need to implement multiple filters in a calculate function, currently I have a measure that sums the amount ([sumVenta]) of the table for example. I need the next filter.

Var vrAnio = 2020

calculate([sumVenta], (TABLE1[Type] ? A && Year - TABLE1[vrAnio]) || (TABLE1[Type] ? B && TABLE1[Year] in 'vrAnio ' vrAnio-1')

That is, if it is type "A" it takes into account the selected year, but if it is of type "B" it takes into account the selected year and the previous year.

TABLA1

guyyearamount
A2020200
B2020150
A2019300
B2019400

Thank you very much for your help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Syndicate_Admin  ,

 

Here are the steps you can follow:

1. Create measrue.

Measure =
var _selectyear=SELECTEDVALUE('Table'[year])
var _guy=CALCULATE(MAX('Table'[guy]),FILTER('Table','Table'[year]=_selectyear))
return
IF(MAX('Table'[guy])="A",
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[year]=_selectyear&&[guy]=MAX('Table'[guy]))),
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),AND(OR('Table'[year]=_selectyear ,'Table'[year]=_selectyear-1),[guy]=MAX('Table'[guy])))))

2. Result.

v-yangliu-msft_0-1619422908179.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi  @Syndicate_Admin  ,

 

Here are the steps you can follow:

1. Create measrue.

Measure =
var _selectyear=SELECTEDVALUE('Table'[year])
var _guy=CALCULATE(MAX('Table'[guy]),FILTER('Table','Table'[year]=_selectyear))
return
IF(MAX('Table'[guy])="A",
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),'Table'[year]=_selectyear&&[guy]=MAX('Table'[guy]))),
CALCULATE(SUM('Table'[amount]),FILTER(ALL('Table'),AND(OR('Table'[year]=_selectyear ,'Table'[year]=_selectyear-1),[guy]=MAX('Table'[guy])))))

2. Result.

v-yangliu-msft_0-1619422908179.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

// For naming conventions and formatting in DAX,
// please refer to this:
// https://www.sqlbi.com/articles/rules-for-dax-code-formatting/

[Meas] =
var SelectedYear = SELECTEDVALUE( T[Year] )
var SelectedType = SELECTEDVALUE( T[Type] )
var Years_ = {
    SelectedYear,
    SelectedYear - INT( SelectedYear = "B" )
}
var Filter_ = 
    TREATAS(
        Years_,
        T[Year]
    )
var Result =
    CALCULATE(
        [sumVenta], // badly named measure
        Filter_
    )
RETURN 
    Result
Syndicate_Admin
Administrator
Administrator

Friends I leave them as I solved it using a measure


MontoTotal ?
Var vrAnio s 2020
var vrRR ? CALCULATE( sum(TABLA1[Amount]), TABLE1[Type]"A", TABLE1[Year]) in .
var vrRP ? CALCULATE( sum(TABLA1[Amount]), TABLE1[Type]-"B", TABLE1[Year])-vrAnio)
return vrRR + vrRP

I don't know if it's the most optimal, but I'll leave them

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Solution Authors