Forum Discussion

danielsouza's avatar
danielsouza
Icon for Helper III rankHelper III
8 years ago
Solved

IF and SWITCH is not working

I'm trying to build a measure using IF or SWITCH, but DAX is not allowing me to load the tables:     Thanks a lot Daniel    
  • danielsouza's avatar
    danielsouza
    8 years ago

    The number 1 means first element?

     

    May I use this too?

     

     

     

    IF(
    	CONTAINS ( 'Fluxo de caixa', 'Fluxo de caixa'[Tipo], "Entrada" );
    	SUM('Fluxo de caixa'[Valor]) + SUM('Fluxo de caixa'[Saldo final de caixa]);
    	SUM('Fluxo de caixa'[Valor]) - SUM('Fluxo de caixa'[Saldo final de caixa])
    )

     

  • Anonymous's avatar
    Anonymous
    8 years ago

    The second argument of FIRSTNONBLANK is rarely used. 1 returns a value of "True" and allows the function to work without an expression there. I think the second argument of FIRSTNONBLANK ought to be optional but I didn't write the language.

     

    CONTAINS won't work the way you're expecting. Does the way I wrote it not give you the results you're looking for?

     

    Try this instead:

     

    CALCULATE(
    	SUM('Fluxo de caixa'[Valor]) + SUM('Fluxo de caixa'[Saldo final de caixa]);
    	FILTER(
    		'Fluxo de caixa';
    		'Fluxo de caixa'[Tipo] = "Entrada"
    	)
    ) +
    CALCULATE(
    	SUM('Fluxo de caixa'[Valor]) - SUM('Fluxo de caixa'[Saldo final de caixa]);
    	FILTER(
    		'Fluxo de caixa';
    		'Fluxo de caixa'[Tipo] <> "Entrada"
    	)
    )