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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
yasbos
Resolver II
Resolver II

conditional all()??

Hi. I have a calculate function. I need to decide on the fly whether it uses all() (based on user input in a checkbox) as one of its arguments. Is this at all possible? Calculate( something, if(checkbox is true, all(dates), do nothing) )

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @yasbos ,

 

Maybe you can try formula like below:

vkongfanfmsft_0-1718242683047.png

ConditionalTotalSales = 
IF(
    [SelectedOption] = "Include All",
    CALCULATE(
        [TotalSales],
        ALL('Calendar')
    ),
    CALCULATE(
        [TotalSales]
    )
)
SelectedOption = SELECTEDVALUE(Checkbox[Option], "Exclude All")
TotalSales = SUM(Sales[Sales])

vkongfanfmsft_1-1718242759637.pngvkongfanfmsft_2-1718242770848.png

 

Best Regards,
Adamk Kong

 

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

Thanks so much, @lbendlin . I forgot to mention that I did know this solution, but I was hoping for a more localized decision because the calculate function that I have is much larger than just one line. I was hoping to modularize the code. Thanks so much for your help, nonetheless.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @yasbos ,

 

Maybe you can try formula like below:

vkongfanfmsft_0-1718242683047.png

ConditionalTotalSales = 
IF(
    [SelectedOption] = "Include All",
    CALCULATE(
        [TotalSales],
        ALL('Calendar')
    ),
    CALCULATE(
        [TotalSales]
    )
)
SelectedOption = SELECTEDVALUE(Checkbox[Option], "Exclude All")
TotalSales = SUM(Sales[Sales])

vkongfanfmsft_1-1718242759637.pngvkongfanfmsft_2-1718242770848.png

 

Best Regards,
Adamk Kong

 

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

Also, thank you again so much for taking the time and putting the efforts into this, @Anonymous . That's awesome!

Thanks so much @Anonymous . I forgot to mention that I did know this solution, but I was hoping for a more localized decision because the calculate function that I have is much larger than just one line. I was hoping to modularize the code. Thanks so much for your help, nonetheless.

lbendlin
Super User
Super User

if(checkbox is true, Calculate( something, all(dates)))

 

You get the "do nothing"  for free if you omit the "else" parameter.

Thanks so much, @lbendlin . I forgot to mention that I did know this solution, but I was hoping for a more localized decision because the calculate function that I have is much larger than just one line. I was hoping to modularize the code. Thanks so much for your help, nonetheless.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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