Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hi Team,
I am building the following map
If you select "Importaciones" the map shows circles with the colors "red" or "Blue" formatted as wether the YoY was negative or positive respectively. But if you select "Exportaciones" then there is no color format.
I am trying to build a measure to select the corresponding YoY calculation for "Importaciones" or "Exportaciones" but I am getting an error.
I am trying to use the following expression:
If Y/Y = VAR AAnteriorE = CALCULATE( SUM('Exportaciones'[FOB_US_DUSLEG]); DATEADD('Calendar'[Date]; -1; YEAR) ) VAR AAnteriorI = CALCULATE( SUM('Importaciones'[CIF_US]); DATEADD('Calendar'[Date]; -1; YEAR) ) IF('Import/Export'[Import/Export])="Exportaciones"; RETURN( DIVIDE(SUM('Exportaciones'[FOB_US_DUSLEG]) - AAnteriorE; AAnteriorE); ) RETURN( DIVIDE(SUM('importaciones'[CIF_US])- AAnteriorI ; AAnteriorI); ) )
But I keep getting syntax error with the IF expression. I have also used
If Y/Y = VAR AAnteriorE = CALCULATE( SUM('Exportaciones'[FOB_US_DUSLEG]); DATEADD('Calendar'[Date]; -1; YEAR) ) VAR AAnteriorI = CALCULATE( SUM('Importaciones'[CIF_US]); DATEADD('Calendar'[Date]; -1; YEAR) ) IF(selectedvalue('Import/Export'[Import/Export])="Exportaciones"); RETURN( DIVIDE(SUM('Exportaciones'[FOB_US_DUSLEG]) - AAnteriorE; AAnteriorE); ) RETURN( DIVIDE(SUM('importaciones'[CIF_US])- AAnteriorI ; AAnteriorI); ) )
But still get syntax error.
Can you guys help me out here?
Thanks,
Reynaldo
Solved! Go to Solution.
It helps if you tell us what the syntax error says. Looking at your code, I noticed a few issues. Here's my attempt at fixing your first expression:
If Y/Y = VAR AAnteriorE = CALCULATE( SUM('Exportaciones'[FOB_US_DUSLEG]); DATEADD('Calendar'[Date]; -1; YEAR) )
VAR AAnteriorI = CALCULATE( SUM('Importaciones'[CIF_US]); DATEADD('Calendar'[Date]; -1; YEAR) )
RETURN IF(SELECTEDVALUE('Import/Export'[Import/Export]) = "Exportaciones";
DIVIDE(SUM('Exportaciones'[FOB_US_DUSLEG]) - AAnteriorE; AAnteriorE);
DIVIDE(SUM('importaciones'[CIF_US]) - AAnteriorI; AAnteriorI); )
Let me know if you get expected results with that measure.
It helps if you tell us what the syntax error says. Looking at your code, I noticed a few issues. Here's my attempt at fixing your first expression:
If Y/Y = VAR AAnteriorE = CALCULATE( SUM('Exportaciones'[FOB_US_DUSLEG]); DATEADD('Calendar'[Date]; -1; YEAR) )
VAR AAnteriorI = CALCULATE( SUM('Importaciones'[CIF_US]); DATEADD('Calendar'[Date]; -1; YEAR) )
RETURN IF(SELECTEDVALUE('Import/Export'[Import/Export]) = "Exportaciones";
DIVIDE(SUM('Exportaciones'[FOB_US_DUSLEG]) - AAnteriorE; AAnteriorE);
DIVIDE(SUM('importaciones'[CIF_US]) - AAnteriorI; AAnteriorI); )
Let me know if you get expected results with that measure.
The error is as follows:
The syntax for 'IF' is incorrect. (DAX(VAR AAnteriorE = CALCULATE( SUM('Exportaciones'[FOB_US_DUSLEG]), DATEADD('Calendar'[Date], -1, YEAR) )VAR AAnteriorI = CALCULATE( SUM('Importaciones'[CIF_US]), DATEADD('Calendar'[Date], -1, YEAR) )IF('Import/Export'[Import/Export])="Exportaciones", RETURN( DIVIDE(SUM('Exportaciones'[FOB_US_DUSLEG]) - AAnteriorE, AAnteriorE), ) RETURN( DIVIDE(SUM('importaciones'[CIF_US])- AAnteriorI , AAnteriorI), ) ) )).
But after a minor fix on your dax I was able to get it up and runnig.
If Y/Y = VAR AAnteriorE = CALCULATE( SUM('Exportaciones'[FOB_US_DUSLEG]); DATEADD('Calendar'[Date]; -1; YEAR) ) VAR AAnteriorI = CALCULATE( SUM('Importaciones'[CIF_US]); DATEADD('Calendar'[Date]; -1; YEAR) ) RETURN IF(SELECTEDVALUE('Import/Export'[Import/Export]) = "Exportaciones"; DIVIDE(SUM('Exportaciones'[FOB_US_DUSLEG]) - AAnteriorE; AAnteriorE); DIVIDE(SUM('importaciones'[CIF_US]) - AAnteriorI; AAnteriorI) )
Thanks,
User | Count |
---|---|
126 | |
108 | |
99 | |
65 | |
62 |
User | Count |
---|---|
137 | |
116 | |
102 | |
71 | |
61 |