That 90's Kid
That 90's Kid

Reputation: 11

Why is Power Query looking for a comma here?

So I have this bit of code:

let 
   Yearpop=0,
   Yeardeath=0

if #"Added index" [#"country-year"] {[Index]} =
   #"Added index" [#"country-year"] {[Index]+1}

then Yeardeath=Yeardeath+[Number of deaths], 
 Yearpop=Yearpop+[Total population]

else (Yeardeath*100000)/Yearpop,
 Yeardeath=0,
 Yearpop=0

The if is underlined in red, and my error message says "Token Comma Expected." Since if statements wouldn't need a comma, and I only defined two variables, I don't get why that error is showing up?

The point of the code is to clean up a data set: I have columns where the # of suicides are sorted by age range and sex, and I want to add up all the deaths and populations to get a total suicide rate for the country that year.

Upvotes: 1

Views: 224

Answers (1)

Storax
Storax

Reputation: 12167

The simple answer is: Because you got the syntax wrong.

Look at the following example which also has a wrong syntax and will not work

let    
   Yearpop=0,    
   Yeardeath=0,    
   if Yeardeath = 1 then result = 1 else result = 0
 in 
    result

You have to use the syntax for let

let    
   Yearpop=0,    
   Yeardeath=0,    
   result = if Yeardeath = 1 then 1 else 0  
 in 
    result

Further reading on let

Upvotes: 2

Related Questions