I absolutely hate when I set off the scanners. Luckily, like you, I came across a guard who did a great job telling me what specifically triggered my bag to go off (I have a thick glasses case which the scanner can't completely see through) and they told me what to do to avoid being flagged (hold the glasses case in your hand and have your arm extended as you walk through).
Every time I do this, you hear the beep of the scanner, the guard will look down at their screen, and see it was my extended glasses case (and nothing on my person) and let me keep on going through. Hopefully this advice will help others to avoid getting pulled aside for something silly every time.