Forum Discussion
Sum a multiplication with if
- 6 years ago
Anonymous Try like. maxx
sumx(SUMMARIZE(ARTICLES;ARTICLES[ART_code];"M1";maxx(ARTICLES;if('ARTICLES'[ART_PRI]<>0; 'ARTICLES'[ART_PRI];'ARTICLES'[ART_PRI_Exact])); "M2";sum('TRANSACTION'[V_qte]));[M1]*[M2])
Anonymous
Try combine with your actual model, I am not clear of how is your model looks like but try something like this:
Measure =
var costtable = SUMMARIZE('Transaction','Transaction'[ART_code], 'Transaction'[Product], 'Transaction'[Client Type],'Transaction'[Cost a], 'Transaction'[Cost b],"Cost", IF('Transaction'[Cost a]<>0,'Transaction'[Cost a],'Transaction'[Cost b]))
Return SUMX(ALLEXCEPT(costtable,[product],[client type]),'Transaction'[Quantity]*[Cost])
The idea is create a column of actual cost, you can store it in the measure like above using Summarize, or just create a calculated column in the transaction table:
cost column= IF('Transaction'[Cost a]<>0,'Transaction'[Cost a],'Transaction'[Cost b])
measure = SUMX(ALLEXCEPT('Transaction',[product],[client type]),[Quantity]*cost column)
Paul Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Anonymous ,
thank you for your answer, I get your idea, but why should I need to create a new table to be able to perform that formula or create a new column in the original table ? I think it complexifies the model by repeating a piece of information already existing. in Qlik, the formula is as follow :
sum({$<V_annee={'$(=max(CalendarYear))'},V_type={'*vente*'}>}V_qte*if(ART_PRI<>0,ART_PRI,ART_PRI_Exact))
without any addition to the tables I have nore any new table (even temporary).
If I have no other choice, I will create a new column in my table ARTICLES, but I rather won't.
Thank you very much for your help !