cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

SWITCH with multiple criteria

I have been struggling with this for a while, but I cannot make progress.

The organization has matters that are billed on a Monthly, Bi-Monthly or Quarterly basis, so on the 1st of any given month all matters meeting the criteria are due for billing.

 

The bill frequency is set forth in a Matters table in a field called BillFrq where the acceptable values are "Monthly", "B1", "B2", "Q1", "Q2" or "Q3" where "Monthly" is self-evident, "B1" indicates matters billed in odd number months, "B2" indicates matters billed in even number months, "Q1" indicates matters billed quarterly in Jan/Apr/Jul/Oct, "Q2" indicates matters billed quarterly in Feb/May/Aug/Nov and "Q3" indicates matters billed in Mar/Jun/Spt/Dec.

I am trying to create a measure identifying all Matters due for billing in any given month, e.,g all matters due for billing in January, or, alternatively, or all matters due for billing in the current month.

 

I have tried this, but I get an error that SWITCH cannot be used to compare True/False and text functions.

 

BillFrq = 
SWITCH (
    CONTAINS ( Matters, Matters[BillFreq], "Monthly" ),
    "Due for billing this month", CONTAINS ( Matters, Matters[BillFreq], "B1" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "1"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "3"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "5"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "7"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "9"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "11",
    "Due for billing this month", CONTAINS ( Matters, Matters[BillFreq], "B2" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "2"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "4"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "6"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "8"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "10"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "12",
    "Due for billing this month", CONTAINS ( Matters, Matters[BillFreq], "Q1" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "1"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "4"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "7"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "10",
    "Due for billing this month", CONTAINS ( Matters, Matters[BillFreq], "Q2" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "2"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "5"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "8"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "11",
    "Due for billing this month", CONTAINS ( Matters, Matters[BillFreq], "Q3" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "3"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "5"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "8"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "12",
    "Due for billing this month", "Not due for billing"
)

Any help appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User III
Super User III

Re: SWITCH with multiple criteria

The DATE formula ask for:
YEAR, MONTH and DAY you are always putting today you don't neeed that.

Replace all of the MONTH( DATE(TODAY(), TODAY(), TODAY())) by simply

MONTH (TODAY())

 

Also to simplyfy you measure try the following code:

 

BillFrq =
VAR Month_Selection =
    MONTH ( TODAY () )
RETURN
    SWITCH (
        TRUE (),
        CONTAINS ( Matters, Matters[BillFreq], "Monthly" ), "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "B1" )
            && Month_Selection IN { 1, 3, 5, 7, 9, 11 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "B2" )
            && Month_Selection IN { 2, 4, 6, 8, 10, 12 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "Q1" )
            && Month_Selection IN { 1, 4, 7, 10 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "Q2" )
            && Month_Selection IN { 2, 5, 8, 11 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "Q3" )
            && Month_Selection IN { 3, 5, 8, 12 }, "Due for billing this month",
        "Not due for billing"
    )

 

Also check the months within each of the in


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog:

Power BI em Português





View solution in original post

7 REPLIES 7
Highlighted
Super User III
Super User III

Re: SWITCH with multiple criteria

Hi @MojoGene ,

 

The first parameter of a switch funcion is the expression so the value you want to compare alonside with the rest of the values in your case you are making it :

CONTAINS ( Matters, Matters[BillFreq], "Monthly" )

And then you are placing the 

"Due for billing this month"

 

In this case you are making the comparision believe that the second part is what you want to return not compare so you need to redo your measure to something similar to this.

 

BillFrq =
SWITCH (
    TRUE (),
    CONTAINS ( Matters, Matters[BillFreq], "Monthly" ), "Due for billing this month",
    CONTAINS ( Matters, Matters[BillFreq], "B1" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "1"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "3"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "5"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "7"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "9"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "11", "Due for billing this month",
    CONTAINS ( Matters, Matters[BillFreq], "B2" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "2"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "4"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "6"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "8"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "10"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "12", "Due for billing this month",
    CONTAINS ( Matters, Matters[BillFreq], "Q1" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "1"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "4"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "7"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "10", "Due for billing this month",
    CONTAINS ( Matters, Matters[BillFreq], "Q2" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "2"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "5"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "8"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "11", "Due for billing this month",
    CONTAINS ( Matters, Matters[BillFreq], "Q3" )
        && MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "3"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "5"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "8"
        || MONTH ( DATE ( TODAY (), TODAY (), TODAY () ) ) = "12", "Due for billing this month",
    "Not due for billing"
)

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog:

Power BI em Português





Highlighted
Helper V
Helper V

Re: SWITCH with multiple criteria

Miguel:

Thanks for the assistance, but here is the error I am getting with your suggestion:

 

Error.png

 
Highlighted
Super User III
Super User III

Re: SWITCH with multiple criteria

You are calculating months so ypu need to add numbers take the "" from the numbers you have in your formula.

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog:

Power BI em Português





Highlighted
Helper V
Helper V

Re: SWITCH with multiple criteria

Miguel:

 

I fixed that problem, but still get this:

Error2.png

Highlighted
Super User III
Super User III

Re: SWITCH with multiple criteria

The DATE formula ask for:
YEAR, MONTH and DAY you are always putting today you don't neeed that.

Replace all of the MONTH( DATE(TODAY(), TODAY(), TODAY())) by simply

MONTH (TODAY())

 

Also to simplyfy you measure try the following code:

 

BillFrq =
VAR Month_Selection =
    MONTH ( TODAY () )
RETURN
    SWITCH (
        TRUE (),
        CONTAINS ( Matters, Matters[BillFreq], "Monthly" ), "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "B1" )
            && Month_Selection IN { 1, 3, 5, 7, 9, 11 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "B2" )
            && Month_Selection IN { 2, 4, 6, 8, 10, 12 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "Q1" )
            && Month_Selection IN { 1, 4, 7, 10 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "Q2" )
            && Month_Selection IN { 2, 5, 8, 11 }, "Due for billing this month",
        CONTAINS ( Matters, Matters[BillFreq], "Q3" )
            && Month_Selection IN { 3, 5, 8, 12 }, "Due for billing this month",
        "Not due for billing"
    )

 

Also check the months within each of the in


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog:

Power BI em Português





View solution in original post

Highlighted
Helper V
Helper V

Re: SWITCH with multiple criteria

Miguel

 

I replaced those MONTH values, but still getting the TRUE/FALSE vs. Text comparison error:

 

Error2.png

Highlighted
Helper V
Helper V

Re: SWITCH with multiple criteria

Miguel:

 

I tried your code and it worked perfectly.

 

Thanks, I have accepted it as a solution.

 

Be well, amigo.

 

g

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Galleries

Galleries

Looking for inspiration on how to present your data? Need instructional videos? Check out our Galleries!

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors