ureech,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
</head>
<body>
<div class="group">
<div data-cost="0" class="item">1</div>
<div data-id="id" data-cost="10" class="item">2</div>
<div data-cost="20" class="item">3</div>
</div>
<div class="group">
<div data-cost="0" class="item">1</div>
<div data-cost="30" class="item">2</div>
<div data-cost="40" class="item">3</div>
</div>
<div class="group">
<div data-cost="0" class="item show">4</div>
<div data-cost="50" data-id="id" class="item show">5</div>
<div data-cost="60" class="item show">6</div>
</div>
<script>
let id = 'id';
let sel = `[data-id="${id}"]`;
let num = [...document.querySelectorAll(sel)].reduce((sum, {dataset : {cost}})=> sum + +cost, 0);
alert(num);
</script>
</body>
</html>