Announcements
cancel
Showing results for
Did you mean:
Contributor

## Using variable with set analysis (YTD)

Hello community, good day.

I am working on the following challenge:

The idea is to generate a bar graph in which the sales per month of the current year are shown vs the sales per month of the previous year: to this point there is no big problem, In the example I am comparing 2016 (pink) vs 2017 (blue):

my problem starts when I want to use a variable within the graph, it shows "Venta" or "Venta20%" (sales * 0.2) according to the selection (dimension)

vMontoVenta IF(SalesNum=1,SUM(Monto_Venta_20),SUM(Monto_Venta))

what I need is to add that variable to the graph, so that it responds to the filter called "KPI". I have tried it as follows but without any result:

if(GetSelectedCount([Año])<>1,
Sum({<[Año]={\$(=max([Año]))} >} '\$ (vMontoVenta)')/1000,
Sum({<[Año]={\$(vAño)}>} '\$ (vMontoVenta)')/1000
)

when using that set analysis the graph shows like this

Any idea what I am doing wrong ?, I appreciate your help

Labels (4)

• ### ytd

3 Replies
Partner - Creator II

Hi Hermilogayosso,

If you passed '=' sign while creating variable the use variable name as it is without any '\$(variable)'

Or else

Remove '=' sign from variable expression and used your final expression '\$(variable)'

Or else

='\$(=IF(SalesNum=1,SUM(Monto_Venta_20),SUM(Monto_Venta)))' into variable vMontoVenta and pass into final expression vMontoVenta

as like if(GetSelectedCount([Año])<>1,
Sum({<[Año]={\$(=max([Año]))} >} vMontoVenta)/1000,
Sum({<[Año]={\$(vAño)}>} vMontoVenta)/1000
)

Contributor
Author

Hi Vishalarote, thanks for the help
I have this variable called vMontoVenta:

= IF (SalesNum = 1, SUM (Amount_Sale_20), SUM (Amount_Sale)

and this measure:

if(GetSelectedCount([Año])<>1,
Sum({<[Año]={\$(=max([Año]))} >} vMontoVenta)/1000,
Sum({<[Año]={\$(vAño)}>} vMontoVenta)/1000
)

but when using them in a graph it doesn't show data

Any other idea why it doesn't work?

Partner - Creator II

Hi Hermilogayosso,

vMontoVenta1:
IF (SalesNum = 1, SUM ({<[Año]={"\$(=max([Año]))"} >}Amount_Sale_20), SUM ({<[Año]={"\$(=max([Año]))"} >}Amount_Sale))

vMontoVenta2:
IF (SalesNum = 1, SUM (Amount_Sale_20), SUM (Amount_Sale))

Final Expression:

if(GetSelectedCount([Año])<>1,
\$(vMontoVenta1)/1000,
\$(vMontoVenta2)/1000
)