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

Advice to reduct this expresion

hello guys i have the next code, but i dont feel comfortable with to many ifs, somebody can give me an advice to short this code?

if(match(ConceptoInline,'Ventas Netas'),
 sum({<Concepto={'VENTAS'},MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Costo de Ventas'),
 sum({<Concepto={'COSTO DE VENTAS'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Gastos de Administración, Comerciales y Generales'),
 sum({<Concepto={'GASTOS DE ADMINISTRACION'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Depreciación y Amortización'),
 sum({<Concepto={'DEPRECIACION ACUMULADA'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Costo Financiero (Neto)'),
 sum({<Concepto={'GASTOS FINANCIEROS'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Fluctuación Cambiaria (Neta)'),
 sum({<Concepto={'OTROS INGRESOS (GASTOS)'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Participación en Subs. y Asoc.'),
 sum({<Concepto={'PARTICIPACION RESULTADOS DE SUBSIDIARIAS Y ASOC.'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000),
 if(match(ConceptoInline,'Impuestos y PTU'),
 sum({<Concepto={'IMPUESTOS Y PTU'}, MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000)
 ,
 if(match(ConceptoInline,'Utilidad Bruta'),
 sum({<Concepto={'VENTAS','COSTO DE VENTAS'},MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000)
 ,
 if(match(ConceptoInline,'EBITDA'),
 sum({<Concepto={'VENTAS','COSTO DE VENTAS','GASTOS DE ADMINISTRACION'},MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000)
  , 
 if(match(ConceptoInline,'Utilidad (Pérdida) antes de Impuestos y PTU'),
 sum({<Concepto={'VENTAS','COSTO DE VENTAS','DEPRECIACION ACUMULADA','GASTOS FINANCIEROS','OTROS INGRESOS (GASTOS)','GASTOS DE ADMINISTRACION','PARTICIPACION RESULTADOS DE SUBSIDIARIAS Y ASOC.'},
 MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000)
 ,
 if(match(ConceptoInline,'Utilidad (Pérdida) Neta'),
 sum({<Concepto={'VENTAS','COSTO DE VENTAS','DEPRECIACION ACUMULADA','GASTOS FINANCIEROS','OTROS INGRESOS (GASTOS)','IMPUESTOS Y PTU','GASTOS DE ADMINISTRACION','PARTICIPACION RESULTADOS DE SUBSIDIARIAS Y ASOC.'},
 MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000)

 

Labels (3)
6 Replies
edwin
Master II
Master II

this really depends on what you want to do.  if you model your data correctly, you can associate your 2 fields ConceptoInline and Concepto

and assuming that you will use this expression in a table, if you have ConceptoInline as a dimension, your expression will be

sum({<MONEDA,[Fecha.Doc]={">=$(=MakeDate(AñoC, 1, 1)) <=$(=MakeDate(AñoC, MesC, DiaC))"}>} ImporteDMBTR/1000)

you will not need the phrase Concepto={'...'} because the data model will do it for you

you may want to share your data and what you want to achieve



Xolink1389
Creator
Creator
Author

conceptoiline its a table inline that contain concepts that dont exist in the original model from concepto(this info come from a SAP Connector)

Xolink1389_1-1692041602367.png

 

This is what i achieve the background in blue are concepts that i have to create in the table inline like this 

ERBancos:
LOAD * INLINE [
    ID,ConceptoInline, ConceptoMatch
    1,'Ventas Netas','VENTAS'
    2,'Costo de Ventas','COSTO DE VENTAS'
    3,'Utilidad Bruta',Null()
    4,'Gastos de Administración, Comerciales y Generales','GASTOS DE ADMINISTRACION'
    5,'EBITDA',Null()
    6,'Depreciación y Amortización','DEPRECIACION ACUMULADA'
    7,'Costo Financiero (Neto)','GASTOS FINANCIEROS'
    8,'Fluctuación Cambiaria (Neta)','OTROS INGRESOS (GASTOS)'
    9,'Participación en Subs. y Asoc.','PARTICIPACION RESULTADOS DE SUBSIDIARIAS Y ASOC.'
    10,'Utilidad (Pérdida) antes de Impuestos y PTU',Null()
    11,'Impuestos y PTU','IMPUESTOS Y PTU'
    12,'Utilidad (Pérdida) Neta',Null()
];



 this is where the concepts came

Set vConcepto =
	 if(num#([G/L Account_HKONT]) >= '4000000000' and num#([G/L Account_HKONT]) <= '4999999999' AND ApplyMap('MapeoCONCEPTOSFBL3N', Num#([G/L Account_HKONT]))<>'PARTICIPACION RESULTADOS DE SUBSIDIARIAS Y ASOC.','VENTAS',
     if(num#([G/L Account_HKONT]) >= '5400000000' and num#([G/L Account_HKONT]) <= '5499999999' AND ApplyMap('MapeoCONCEPTOSFBL3N', Num#([G/L Account_HKONT]))<>'DEPRECIACION ACUMULADA', 'COSTO DE VENTAS' ,
     if(num#([G/L Account_HKONT]) >= '5500000000' and num#([G/L Account_HKONT]) <= '5599999999' AND ApplyMap('MapeoCONCEPTOSFBL3N', Num#([G/L Account_HKONT]))<>'IMPUESTOS Y PTU', 'GASTOS DE ADMINISTRACION' ,
     if(num#([G/L Account_HKONT]) >= '6000000000' and num#([G/L Account_HKONT]) <= '7999999999' AND ApplyMap('MapeoCONCEPTOSFBL3N', Num#([G/L Account_HKONT]))<>'OTROS INGRESOS (GASTOS)', 'GASTOS FINANCIEROS',
	 Coalesce(
     ApplyMap('MapeoCONCEPTOSCxC', num#([G/L Account_HKONT]),null()), 
     ApplyMap('MapeoCONCEPTOSCxP',num#([G/L Account_HKONT]), null()), 
     ApplyMap('MapeoCONCEPTOSFBL3N', Num#([G/L Account_HKONT]), NULL())
     		)))));

i needed to split the concepts in cxc,cxp and fbl3n, thats what i did this, in 


edwin
Master II
Master II

pls post a pic of your DM

this line is incorrect:

'Gastos de Administración, Comerciales y Generales','GASTOS DE ADMINISTRACION'

it has to be two lines:

Gastos de Administración, GASTOS DE ADMINISTRACION
Comerciales y Generales,GASTOS DE ADMINISTRACION

 

Xolink1389
Creator
Creator
Author

and because conceptoInline its my refer dimension to this, i need to compare when ConceptoInline iqual to 'Ventas Netas' use the CONCEPTO that match with de account ConceptoInline it just a reference is not associate to anytable

edwin
Master II
Master II

the point is if the association between the two fields is correct lik will handle the comparison for you

edwin
Master II
Master II

not sure why you need to store values in a variable during load script - you may have to provide more info to understand what you are doing.  also a DM would help, showing the expression for fields that anyone helping you cant see where they are coming from will not help.  only you can see what these fields are and weher they are coming from so help others help you