Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need Help with function If

Hello,

I have a problem to calculate a function.

I have two document types, an invoice and a credit note.

When I have invoice the amount is positive, but when I have a credit note I will wish him to return a negative amount.

I tried this formula but it does me no return value:

If( (Type_Facture) = 'Avoir', sum({ <Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}>} -MontantHT_Ligne) or  If( (Type_Facture) = 'Facture', sum({ <Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}>} MontantHT_Ligne)

Anyone can help me?

Best regards

4 Replies
Anonymous
Not applicable
Author

Hi,

Looks like there is an issue with your syntax

Please try this and see if it works:

If( (Type_Facture = 'Avoir', sum({ <Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}>} -MontantHT_Ligne), If( Type_Facture = 'Facture', sum({ <Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}>} MontantHT_Ligne)

asgardd2
Creator III
Creator III

You need change you expression with correct syntax.

If( Type_Facture = 'Avoir',

sum({ <Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}>} -MontantHT_Ligne),

  If( Type_Facture = 'Facture',

   sum({ <Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}>} MontantHT_Ligne)

     )

  )

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Something like this?

sum({<Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}, Type_Facture = {'Facture'}>} MontantHT_Ligne)

- sum({<Date_Facture={'>=$(vDateDebCalendrier)<=$(vDateFinCalendrier)'}, Type_Facture = {'Avoir'}>} MontantHT_Ligne)

Because Invoice types can change per row, the IF() should be placed inside your sum() aggregation function. And because an IF() that is executed once per row is incredibly bad for performance when processing large amounts of invoices, we use set analysis again to separate Invoices from Credit Notes.

Bonne chance,

Peter

Not applicable
Author

Thanks a lot it's work perfectly

Best regards