"SUMPRODUCT"Formula Help!


#1

I’m trying to port over my UPC check digit calculator formula over to airtable but they don’t support “sumproduct”. Here is the formula, can someone help me find a solution in AT?

Excel Formula
=A1 & 10 - MOD( SUMPRODUCT(MID(A1, {1,2,3,4,5,6,7,8,9,10,11}, 1) * {3,1,3,1,3,1,3,1,3,1,3}), 10)


#2

I can’t provide an Airtable equivalent for SUMPRODUCT(), as Airtable doesn’t currently support array arithmetic, but I can provide you with a formula to calculate the check digit.[1]

This algorithm assumes your 11-digit UPC code is stored in a field called, unsurprisingly, {UPC}. This formula should work with both number and single-line text {UPC} fields. I’ll give you two versions of the formula; the first simply returns a single check digit, which should be appended to your 11-digit code.

Note: There are undoubtedly easier and/or more elegant ways to perform this function; I stopped once it started working. If you want something prettier, knock yourself out.

IF(
    MOD(
        ((
            VALUE(MID(UPC&'',LEN(UPC&''),1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-2,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-4,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-6,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-8,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-10,1))
            )*3+
            VALUE(MID(UPC&'',LEN(UPC&'')-1,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-3,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-5,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-7,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-9,1))
            ),
        10
        )=0,
    0,
    10-MOD(
        ((
            VALUE(MID(UPC&'',LEN(UPC&''),1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-2,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-4,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-6,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-8,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-10,1))
            )*3+
            VALUE(MID(UPC&'',LEN(UPC&'')-1,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-3,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-5,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-7,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-9,1))
            ),
        10
        )
    )

The second version returns the completed 12-digit UPC:

REPT('0',11-LEN(UPC&''))&UPC&
IF(
    MOD(
        ((
            VALUE(MID(UPC&'',LEN(UPC&''),1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-2,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-4,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-6,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-8,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-10,1))
            )*3+
            VALUE(MID(UPC&'',LEN(UPC&'')-1,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-3,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-5,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-7,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-9,1))
            ),
        10
        )=0,
    0,
    10-MOD(
        ((
            VALUE(MID(UPC&'',LEN(UPC&''),1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-2,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-4,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-6,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-8,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-10,1))
            )*3+
            VALUE(MID(UPC&'',LEN(UPC&'')-1,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-3,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-5,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-7,1))+
            VALUE(MID(UPC&'',LEN(UPC&'')-9,1))
            ),
        10
        )
    )

You can find a demonstration base here that demonstrates the use of this formula with both number and text fields.


  1. At least, I think it does. Please test this with a stack of real-life UPCs before letting it venture out on its own…

#3

Dude your a gem!
Worked like a charm.
Thank you so much