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
bmpi
Frequent Visitor

Improvement of IF-CALCULATE calculation

I have a formula that runs slow, which I am looking to improve..

 

Is there a more efficient way to write this formula?

(I want to return 0 if the colour is not "blue" for average calculation purposes)

 

In addition I want to return blank on all dates larger than today, but I did not find a way to make this work for this calculation.

 

# Blue People =

 IF(

    ISBLANK(CALCULATE([# People], Product[Colour] = "Blue")) ,

       0,

     CALCULATE([# People], Product[Colour] = "Blue"))

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

hi @bmpi 

please try

=
COALESCE ( CALCULATE ( [# People], Product[Colour] = "Blue" ), 0 )

View solution in original post

5 REPLIES 5
Syk
Super User
Super User

try something like this

Blue people =
var BluePeeps = CALCULATE([# People],Product[Colour]="Blue")
RETURN if(MAX('Date'[Date])<TODAY(), BluePeeps,0)
bmpi
Frequent Visitor

Thanks!

 

Ended up with a mix of both suggestions:

 

# Blue People  =

VAR BluePeeps = CALCULATE([# People], Product[Colour] = "Blue"))
VAR COAL = COALESCE(BluePeeps,0)
RETURN IF(max(dimDate[Date]) <= TODAY(), COAL, BLANK())

Good to hear! For a bit simpler return you can leave off the last BLANK(). If you don't include anything for the false part of the if statement, it will automatically return blank!

tamerj1
Super User
Super User

hi @bmpi 

please try

=
COALESCE ( CALCULATE ( [# People], Product[Colour] = "Blue" ), 0 )

bmpi
Frequent Visitor

Thanks, work like a charm.

 

Ended up with a mix of both suggestions:

 

# Blue People  =

VAR BluePeeps = CALCULATE([# People], Product[Colour] = "Blue"))
VAR COAL = COALESCE(BluePeeps,0)
RETURN IF(max(dimDate[Date]) <= TODAY(), COAL, BLANK())

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.