I'm using power apps to bulk upload excel files to sharepoint. I have a flow that triggers when these files are modified or created and creates or updates list items based on some key/value pairs available.
The flow works fine until I hit some bad data in my excel files. Specifically DATE fields. They vary from null, excel serial dates, and dd-MMM-yyyy. For documents without excel serial dates I simply use:
if(equals(items('Apply_to_each_10')?['PROJ QTR1'],''),null,items('Apply_to_each_10')?['PROJ QTR1']) - for example
This handles the null values without issue but once Excel Serial dates are erroneously introduced, I'm at a loss. I've attempted multiple different variations, used null-coalescing operators to get around nested if statements...I'm stumped. Below are some examples of my attempts following power automates documentation rules:
Attempt 1 // cannot get 'isNumeric' to hit.
if(equals(items('Apply_to_each_6')?['DEPARTURE_DATE'],''),null,IsNumeric(items('Apply_to_each_6')?['DEPARTURE_DATE']),formatDateTime(addDays('12-30-1899',int(items('Apply_to_each_6)?['DEPARTURE_DATE'])),'dd-MMM-yyyy'), items('Apply_to_each_6')?['DEPARTURE_DATE'])
Standalone // works but null is still an issue
IsNumeric(items('Apply_to_each_6')?['DEPARTURE_DATE'])) {formatDateTime(addDays('12-30-1899', int(items('Apply_to_each_6')?['DEPARTURE_DATE'])), 'dd-MMM-yyyy')
Attempt 2 //else if doesn't function that way...no go
if(equals(items('Apply_to_each_6')?['DEPARTURE_DATE'],''),null,items('Apply_to_each_6')?['DEPARTURE_DATE']),else if(isNumeric(items('Apply_to_each_6')?['DEPARTURE_DATE']),formatDateTime(addDays('12-30-1899', int(items('Apply_to_each_6')?['DEPARTURE_DATE']),'dd-MMM-yyyy'),items('Apply_to_each_6')?['DEPARTURE_DATE'])
Attempt 3 // swapping equals and forcing a reformat...testing. Script VALID from power automate, Woohoo!
if(isempty(items('Apply_to_each_6')?['DEPARTURE_DATE']),null,formatDateTime(addDays('12-30-1899', int(items('Apply_to_each_6')?['DEPARTURE_DATE']),'dd-MMM-yyyy'),items('Apply_to_each_6')?['DEPARTURE_DATE']))
// Attempt 3 is throwing an error because forcing dd-MMM-yyyy through the int() function isn't possible. I need find nested if statement workaround.
Attempt 4 // nested if's // nested if's are not allowed in powerfx...fml.
if(isempty(items('Apply_to_each_6')?['DEPARTURE_DATE']),null,if(isNumeric(items('Apply_to_each_6')?['DEPARTURE_DATE']),
formatDateTime(addDays('12-30-1899', int(items('Apply_to_each_6')?['DEPARTURE_DATE'])),'dd-MMM-yyyy'),items('Apply_to_each_6')?['DEPARTURE_DATE'])))
Attempt 5 // last chance today... // the '?' prior to formatDateTime is a null-coalescing operator...we may be onto something...
if(equals(items('Apply_to_each_6')?['DEPARTURE_DATE'],''),null,isNumeric(items('Apply_to_each_6')?['DEPARTURE_DATE']) ? formatDateTime(addDays('12-30-1899', int(items('Apply_to_each_6')?['DEPARTURE_DATE'])),'dd-MMM-yyyy') : items('Apply_to_each_6')?['DEPARTURE_DATE']))
Attempt 6 // Lets null-coalesce them ALL !!!
return isempty(items('Apply_to_each_6')?['DEPARTURE_DATE'])?null : isNumeric(items('Apply_to_each_6')?['DEPARTURE_DATE']) ? formatDateTime(addDays('12-30-1899', int(items('Apply_to_each_6')?['DEPARTURE_DATE'])),'dd-MMM-yyyy') : items('Apply_to_each_6')?['DEPARTURE_DATE'])
// isempty doesn't work because it's stopping at the first null value and attempting to null it. Script invalid.
As you can see, I was also all over the place with syntax trying various methods...HELP