Forum Discussion
SWITCH with multiple criteria
- 6 years ago
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
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"
)
Miguel:
Thanks for the assistance, but here is the error I am getting with your suggestion:
- MFelix6 years agoSuper UserYou are calculating months so ypu need to add numbers take the "" from the numbers you have in your formula.
- MojoGene6 years agoPost Patron
Miguel:
I fixed that problem, but still get this:
- MFelix6 years agoSuper User
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