Help between Notion users

It's free & easy

Receive points, vote and give the solution

1vote

# Conditional formula for days

I have a Notion question I can't find the answer to.

For example, my weekly goal for a habit is 3 days a week. But when I mark 3 out of 7 days as chechbox, it shows 43%. Actually, I would like it to show 100% since my goal is already 3 days.

It only shows the habit completed 7 days a week as 100%.

How can I do this, any ideas?

The current formula is as follows,

``round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1"))) / 7) / 100``

1vote

Hey,

here are two formulas that will give you the desired effect.

This first one allows the percentage to go over 100% all the way up to 233% when the full week is completed.

``````round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Thu"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1"))) / 3) / 100
``````

This second one goes only up to 100% even when you complete more than 3 days.

``min(1, round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Thu"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1"))) / 3) / 100)``

I would also recommend replacing the number "3" (your weekly goal) in the formula with prop("Goal") and adding a property "Goal" to your database. This way you can have different goal for each habit if needed

The two formulas would look like this then:

1) Allows over 100%:

``round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Thu"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1"))) / prop("Goal")) / 100``

2) Upto 100%:

``min(1, round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Thu"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1"))) / prop("Goal")) / 100)``

0vote

### azofeifa commented Jul 24, 2023

Hi Martin,

Did you look at the image? 'Goal' property is already there.

I need something like below but I couldn't achieve it exactly. I was able to fix them all to 3 with the formula you gave :) Even if Goal is 6 days, it shows 100% when chechbox above 3 is checked.

I think I need this,

If '1 day/week' is selected as Goal, when 1 checkbox is checked, the progress bar is 100%

If '2 days/week' is selected as Goal, when 2 checkboxes are checked, the progress bar is 100%

..
..
..

If '7 days/week' is selected as Goal, the progress bar is 100% when the 7 checkbox is checked.

1vote

### Martin_SystemsHill commented Jul 24, 2023

Hey,

BTW I was just going through your formula again and please be carful about the days of the week. You have "Tue" there twice and you are missing "Thu". I would recommend using my formula exactly instead of adjusting yours to make sure it works.

Anyways. Here are the formulas that are going to work for your exact case. I tested it in my database and it works.

What it does is that it takes the first character from the property "Goal", changes it into a number and applies it to the formula.

1) Can go over 100%

``round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Thu"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1"))) / toNumber(slice(prop("Goal"), 0, 1))) / 100``

2) Upto 100%

``min(1, round(100 * (toNumber(replace(prop("Mon"), "true", "1")) + toNumber(replace(prop("Tue"), "true", "1")) + toNumber(replace(prop("Wed"), "true", "1")) + toNumber(replace(prop("Thu"), "true", "1")) + toNumber(replace(prop("Fri"), "true", "1")) + toNumber(replace(prop("Sat"), "true", "1")) + toNumber(replace(prop("Sun"), "true", "1"))) / toNumber(slice(prop("Goal"), 0, 1))) / 100)``

1vote

### azofeifa commented Jul 24, 2023

Worked! great, thank you Martin.

1vote

### Martin_SystemsHill commented Jul 25, 2023

Great. I am glad I could help.

Thanks.

Martin

0vote

### azofeifa commented Jul 31, 2023

Done!

Thank you Martin.