Forum Discussion

yasbos's avatar
yasbos
Resolver II
2 years ago
Solved

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) )

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi yasbos ,

     

    Maybe you can try formula like below:

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

     

    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.

  • yasbos's avatar
    yasbos
    2 years ago

    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.

5 Replies

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

     

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

    • yasbos's avatar
      yasbos
      Resolver II

      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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi yasbos ,

     

    Maybe you can try formula like below:

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

     

    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.

    • yasbos's avatar
      yasbos
      Resolver II

      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.

    • yasbos's avatar
      yasbos
      Resolver II

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