[Solved] IF function with AND/OR tests
-
bniccum1@cfl.rr.com
- Posts: 5
- Joined: Sat Jun 17, 2023 8:04 pm
[Solved] IF function with AND/OR tests
Hello,
I'm hoping someone will have a solution for what I am trying to accomplish. I have tried numerous variations of "IF", "IF(AND(" along with "IF(OR(" arguments to no avail with consistent accuracy. I don't know if it's due to possible circular issues, the formula syntax or simply that I'm wanting something that's just not doable in OO. I've included a snapshot of the spread sheet layout.
In short, what I am trying to do is compare kWh usages from day to day with daily temperatures factored in. If the temp was lower the previous day vs today but kWh usage was higher today than the previous day, then I would like the corresponding cell in columnh "I" to result in either TRUE or FALSE. I think maybe the problem I'm having is related to a circular issue but regardless, while in this example the results accurate with respect to one set of cells but not neccesarily for the other set. Maybe the result I'm looking for just isn't achievable.
I'm hoping someone will have a solution for what I am trying to accomplish. I have tried numerous variations of "IF", "IF(AND(" along with "IF(OR(" arguments to no avail with consistent accuracy. I don't know if it's due to possible circular issues, the formula syntax or simply that I'm wanting something that's just not doable in OO. I've included a snapshot of the spread sheet layout.
In short, what I am trying to do is compare kWh usages from day to day with daily temperatures factored in. If the temp was lower the previous day vs today but kWh usage was higher today than the previous day, then I would like the corresponding cell in columnh "I" to result in either TRUE or FALSE. I think maybe the problem I'm having is related to a circular issue but regardless, while in this example the results accurate with respect to one set of cells but not neccesarily for the other set. Maybe the result I'm looking for just isn't achievable.
- Attachments
-
- Sample sheet
- chart.jpg (58.61 KiB) Viewed 3586 times
Last edited by MrProgrammer on Tue Jul 25, 2023 6:35 pm, edited 2 times in total.
Reason: Edited topic's subject
Reason: Edited topic's subject
OpenOffice 4.1.5 on Windows 7 Pro
Re: Help with IF function
Please upload a real, ODF type sample file here.
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Help with IF function
I agree a spreadsheet is needed for anyone to help efficiently. It should include at least one case where the formula does not work. As far as I can tell, all the results in your image are correct.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Help with IF function
i think this works for you
- Attachments
-
- if staement.ods
- (14.14 KiB) Downloaded 128 times
openOffice 4.0.0 on macOS
Re: Help with IF function
I'm not seeing a problem with your sheet. You say
"kWh usage was higher today than the previous day" translates to column D being positive.
Your formula
properly returns the text "true" if both conditions are met and it returns FALSE otherwise. What is not working as you expect it to?
You could simplify the formula to
which would return TRUE if the two conditions are met and FALSE otherwise.
"temp was lower the previous day" translates to column H, which is Temp_today - Temp_yesterday, being positive.If the temp was lower the previous day vs today but kWh usage was higher today than the previous day, then I would like the corresponding cell in columnh "I" to result in either TRUE or FALSE
"kWh usage was higher today than the previous day" translates to column D being positive.
Your formula
Code: Select all
=IF(AND(H7>0;D7>0);"true")You could simplify the formula to
Code: Select all
=AND(H7>0;D7>0)OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Help with IF function
If you want numeric (Boolean) result, then the logical values of the function must be representated by constants 1/0 or functions TRUE()/FALSE() instead of the string "true".i think this works for you
Tibor Kovacs, Hungary; LO7.5.8/25.8.5.2 /Win7-10-11 x64Prof.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
PortableApps: LO3.3.0-25.8.5.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Re: Help with IF function
Your formula recognizes a correlation between temperature change and energy usage only with temperature change in one direction. Try instead.
Code: Select all
=(G13>F13)=(C13<B13)AOO 4.1.16 & LO 25.8.3 on Windows 10
Re: Help with IF function
j14 has boolean example - his sheet has "True". "false " text....
openOffice 4.0.0 on macOS
-
bniccum1@cfl.rr.com
- Posts: 5
- Joined: Sat Jun 17, 2023 8:04 pm
Re: Help with IF function
Thank you! I actually got it to work but using this ...Alex1 wrote: ↑Sun Jun 18, 2023 9:15 am Your formula recognizes a correlation between temperature change and energy usage only with temperature change in one direction. Tryinstead.Code: Select all
=(G13>F13)=(C13<B13)
=IF(AND(F13>G13;C13>B13);TRUE;FALSE)
Your way is much simpler and returns exactly the same results I have been looking for. Thank you to everyone who chimed in!!
OpenOffice 4.1.5 on Windows 7 Pro
-
bniccum1@cfl.rr.com
- Posts: 5
- Joined: Sat Jun 17, 2023 8:04 pm
Re: Help with IF function
Thank you! Your solution also works but to get the correct result I did have to change the D13>0 to D13<0 based on the input values in cells within column D sometimes resulting in negative number. I greatly appreciate your feedback and help!!FJCC wrote: ↑Sun Jun 18, 2023 6:17 am I'm not seeing a problem with your sheet. You say"temp was lower the previous day" translates to column H, which is Temp_today - Temp_yesterday, being positive.If the temp was lower the previous day vs today but kWh usage was higher today than the previous day, then I would like the corresponding cell in columnh "I" to result in either TRUE or FALSE
"kWh usage was higher today than the previous day" translates to column D being positive.
Your formulaproperly returns the text "true" if both conditions are met and it returns FALSE otherwise. What is not working as you expect it to?Code: Select all
=IF(AND(H7>0;D7>0);"true")
You could simplify the formula towhich would return TRUE if the two conditions are met and FALSE otherwise.Code: Select all
=AND(H7>0;D7>0)
OpenOffice 4.1.5 on Windows 7 Pro
-
bniccum1@cfl.rr.com
- Posts: 5
- Joined: Sat Jun 17, 2023 8:04 pm
Re: [Solved] Help with IF function
I'm back!! I thought I had this worked out but nope.
If the temperature today was hotter than yesterday and the kWh usage was greater, then that should be expected. But if the temperature today was cooler than yesterday and the kWh usage was greater than yesterday, that would indicate a possible issue and shouldn't be true. It would indicate that possibly something else in the home was using more power than it should be i;e; water heater, clothes dryer, refrigeration units, etc, etc. Tthe only energy consumption that should be directly affected by outsiude temperature would be the heating/cooling system and to some degree the hot water heater based on it's thermostat settings.
While the current formula I'm using is partially correct, it's not accounting for all variations. In the argument =IF(AND(F4>G4;C4>B4);1;0) the return value is "false" which is correct with respect to all arguments. But in =IF(AND(F6>G6;C6>B6);1;0) the argument is only ½ true. While the the temperature the previous day was cooler than today, the kWh usage was almost 10% higher. One would expect that given the cooler outsiude temperature on the previous day that the heating/cooling system would use less energy yet still the overall usage was higher which IMHO would indicate that issue I'm referring to.
Maybe I'm reaching for the stars here but iIt just seems to me that there must be a formula for what I'm trying to do. Maybe I just need additional data to make the argument work correctly but I'm not an expert with spreadsheets by any stretch. I've attached the spreadsheet.
If the temperature today was hotter than yesterday and the kWh usage was greater, then that should be expected. But if the temperature today was cooler than yesterday and the kWh usage was greater than yesterday, that would indicate a possible issue and shouldn't be true. It would indicate that possibly something else in the home was using more power than it should be i;e; water heater, clothes dryer, refrigeration units, etc, etc. Tthe only energy consumption that should be directly affected by outsiude temperature would be the heating/cooling system and to some degree the hot water heater based on it's thermostat settings.
While the current formula I'm using is partially correct, it's not accounting for all variations. In the argument =IF(AND(F4>G4;C4>B4);1;0) the return value is "false" which is correct with respect to all arguments. But in =IF(AND(F6>G6;C6>B6);1;0) the argument is only ½ true. While the the temperature the previous day was cooler than today, the kWh usage was almost 10% higher. One would expect that given the cooler outsiude temperature on the previous day that the heating/cooling system would use less energy yet still the overall usage was higher which IMHO would indicate that issue I'm referring to.
Maybe I'm reaching for the stars here but iIt just seems to me that there must be a formula for what I'm trying to do. Maybe I just need additional data to make the argument work correctly but I'm not an expert with spreadsheets by any stretch. I've attached the spreadsheet.
- Attachments
-
- EnergyUsageExport.ods
- (91.78 KiB) Downloaded 91 times
OpenOffice 4.1.5 on Windows 7 Pro
Re: [Solved] Help with IF function
quickly responding - nested if's might be what you need...
openOffice 4.0.0 on macOS
Re: [Solved] Help with IF function
I think you want to return TRUE if (today's temperature is higher AND yesterday's energy use is higher) OR (today's temperature is lower AND yesterday's energy use is lower). That would be
The IF() function isn't doing anything useful in that formula. You could use
which directly returns TRUE or FALSE.
Code: Select all
=IF(OR(AND(F6>G6;C6>B6);AND(F6<G6;C6<B6));1;0)Code: Select all
OR(AND(F6>G6;C6>B6);AND(F6<G6;C6<B6))OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
-
bniccum1@cfl.rr.com
- Posts: 5
- Joined: Sat Jun 17, 2023 8:04 pm
Re: [Solved] Help with IF function
Thank you! Both of your suggestions work and yes, the IF() function wasn't necessary at all.FJCC wrote: ↑Mon Jun 26, 2023 6:34 pm I think you want to return TRUE if (today's temperature is higher AND yesterday's energy use is higher) OR (today's temperature is lower AND yesterday's energy use is lower). That would beThe IF() function isn't doing anything useful in that formula. You could useCode: Select all
=IF(OR(AND(F6>G6;C6>B6);AND(F6<G6;C6<B6));1;0)which directly returns TRUE or FALSE.Code: Select all
OR(AND(F6>G6;C6>B6);AND(F6<G6;C6<B6))
OpenOffice 4.1.5 on Windows 7 Pro