Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
danielsouza
Helper III
Helper III

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:

 

if.JPG

 

Thanks a lot

Daniel

 

 

2 ACCEPTED SOLUTIONS

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])
)

 

View solution in original post

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"
	)
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

8 REPLIES 8
KHorseman
Community Champion
Community Champion

You can't refer to naked tables or columns in measures, you have to aggregate the data (sum, min, max, firstnonblank, etc.).





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I see.

 

But I would like to work with string:

 

Saldo final = IF('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]))

 

Fluxo de caixa[Tipo] only has text.

 

How can I aggregate the data?

 

Firstnonblank





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Saldo final = IF(FIRSTNONBLANK('Fluxo de caixa'[Tipo];'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]))

 

Is not working, IF column Tipo contains "Entrada", sum value in valor and value in Saldo final de caixa...

 

Any clue?

Your syntax for FIRSTNONBLANK is slightly wrong.

 

IF(
	FIRSTNONBLANK('Fluxo de caixa'[Tipo]; 1) = "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])
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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])
)

 

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"
	)
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Yes, worked very well! Now I know how to use the IF statement.

 

Nice line of thought, I gonna use this last suggestion!

 

Thanks a lot!

Daniel

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.