Forum Discussion
New column needed with calculated value on a numeric field based on non-numeric column value
I'm trying create a column using a numeric field based on the value of a non-numeric column. I'm using An IF Statement as follows:]
5 Replies
- Greg_Deckler
Community Champion
Anonymous Strange. Worked flawlessly for me. See attached PBIX below signature. You should at least get the original Hour column values. I would also recommend switching over to using a SWITCH(TRUE(),...) statement to avoid nested IF statements.
- AnonymousNot applicable
Yes, very interesting. It's not working for me at all. I also tried using SWITCH to not have to do two separate columns and IF statements, but that also didn't work. When I tried to open your file, it says I'm using an old version of Power BI and need to update. That may be the problem right there. Will update and retry and will let you know. Thanks for your help, Greg!
- AnonymousNot applicable
Here's the results I get:
😞
- AnonymousNot applicable
Greetings and Happy St. Patty's Day, Greg. So I created a test data sample of my own and put it into PowerBI and was not able to get it to work. Unfortunately, I don't have the option to attach a file or I would include the .xlsx test data and .pbix file. Here's a screen shot of the data in the .xlsx file:
and a screen shot of the table in .pbix:
Associated DAX Code:
TOD1 = IF(AND('Test Data'[Hour Data] > 12, 'Test Data'[AM-PM] = "PM"),'Test Data'[Hour Data] + 12, 'Test Data'[Hour Data])andTOD2 = IF(AND('Test Data'[Hour] > 12, 'Test Data'[AM-PM] = "PM"),'Test Data'[Hour] + 12, 'Test Data'[Hour])Still not working. Have no idea why. Unlikely to work even using SWITCH (TRUE() ...) if this doesn't work.