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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Syndicate_Admin
Administrator
Administrator

Add an IF within a variable

Hello everyone!!!
I am performing the following measurement in dax:

CALCULATION =

VAR OPERATION = calculate(
SUM(Table1[amount]),
Table1[black/white]="white"
)

VAR OPERACION2 = calculate(
sum(Tabla1[monto2]),
Tabla1[blanco/negro]="blanco"
)

TOTAL VAR = DIVIDE(operation,operation2,0)

RETURN
TOTAL

What I need is that when the field [black/white] = "black" puts as a value "NC" otherwise do the calculation I wrote at the beginning. Try to put an if or switch but I do not know how to make it read the value of the column.
Can you help me? Thank you.

3 REPLIES 3
Syndicate_Admin
Administrator
Administrator

Thanks for the reply and suppose I put Blank, as I do??? that's what I need to know how to put the if within the measure I wrote. Thank you.

 

 

 

CALCULATION =
if(Table1[black/white]="black","NC",
format(divide(SUM(Table1[amount]),sum(Table1[amount2])),"#.#%"))

 

 

or (for blank)

 

 

CALCULATION =
if(Table1[black/white]="white",
divide(SUM(Table1[amount]),sum(Table1[amount2])),"#.#%")

 

 

This may or may not work depending on your setup.  Provide sample data if you want more assistance.

 

lbendlin
Super User
Super User

You cannot return a text string or a number in the same measure.  All results need to be of the same type (or BLANK).  Change your measure to return BLANK instead of NC,  or convert all output to text.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.