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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Can I use a conditional filter expression?

I'm trying to create a dynamic measure that can be configured using a drop-down. This way someone can choose the period over which to sum sales. I already got this working with Month / MQT / MAT, by using the following measure:

 

# Sales = CALCULATE(
     [Total Sales], 
     DATESINPERIOD(
         'Date'[Date];
        MAX('Date'[Date]);
        SELECTEDVALUE(Period[offset]);
        MONTH
    )
)
Now I'm looking to add a YTD. Unfortunataly I can't use the DATESINPERIOD because of the fact that the amount of months changes on regular basis. I'm looking for a way to conditionally choose between DATESYTD & DATESINPERIOD. Unfortunataly it seems I can't use an IF statement like this, since that will result in an error "A function 'FILTER' has been used in a True/False expression that is used as a table filter expression". Do I need to do this differently?
 
IF(
   condition = true;
   DATESYTD(....);
   DATESINPERIOD(...);
)
1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User


@Anonymous wrote:
Unfortunataly it seems I can't use an IF statement like this, since that will result in an error "A function 'FILTER' has been used in a True/False expression that is used as a table filter expression". Do I need to do this differently?

Both DATESYTD and DATESINPERIOD return tables and unfortunately you can't return a table value from the IF function. So you will need to put your calculate inside the IF so that it is returning a scalar value.

 

eg.

 

# Sales = 
IF(
  condition = true;
    CALCULATE(
       [Total Sales], 
       DATESYTD( ... )
  );
  CALCULATE(
       [Total Sales], 
       DATESINPERIOD( ... )
  );
)

View solution in original post

1 REPLY 1
d_gosbell
Super User
Super User


@Anonymous wrote:
Unfortunataly it seems I can't use an IF statement like this, since that will result in an error "A function 'FILTER' has been used in a True/False expression that is used as a table filter expression". Do I need to do this differently?

Both DATESYTD and DATESINPERIOD return tables and unfortunately you can't return a table value from the IF function. So you will need to put your calculate inside the IF so that it is returning a scalar value.

 

eg.

 

# Sales = 
IF(
  condition = true;
    CALCULATE(
       [Total Sales], 
       DATESYTD( ... )
  );
  CALCULATE(
       [Total Sales], 
       DATESINPERIOD( ... )
  );
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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