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
daledale
Frequent Visitor

Help with IF DAX

Hi everyone,

 

I'm stuck trying to generate a Measure with IF.

What I want to do would be something like IF the Variance is <0,"Better","Worse".

 

The issue is that the Variance is an attribute in an unpivoted table. Ex:
NODE-Category-Attribute -   Value
1              A          Q1                  $
1              A           Q2                  $
1              A          Forecast           $
1              A          Variance          $
1              B          Q1                  $
1              B           Q2                  $
1              B          Forecast           $
1              B          Variance          $

And so on... 
So what I want is to create an IF Measure that shows either "Better" or "Worse" according to the Value for the Variance Attribute.. 

Is there a way to do that? I've tryied splitting the data in different tables also but I'm not able to solve it... 

Thanks in advance

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi daledale, 

Yes, you could try to create a calculated column like below to get your result 

Column = if(T5[Attribute]="Variance" && T5[Value]>0, 1,2)

or you could try to use M code to achieve this goal

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIE4kAQw9BUKVYHScwIJGaAIuaWX5SanFhcApJBkQhLLMpMzEtOBTIRpjjBTTZCFTPCUIbVYCdUg3WBWmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Node = _t, Category = _t, Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Node", Int64.Type}, {"Category", type text}, {"Attribute", type text}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Attribute]="Variance" and  [Value]>0 then 1 else 2)
in
    #"Added Custom"

By the way, what did you mean of "I've tryied splitting the data in different tables also but I'm not able to solve it"? If possible, could you please inform me more detailed information(such as your expected output).

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
dax
Community Support
Community Support

Hi daledale, 

Yes, you could try to create a calculated column like below to get your result 

Column = if(T5[Attribute]="Variance" && T5[Value]>0, 1,2)

or you could try to use M code to achieve this goal

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIE4kAQw9BUKVYHScwIJGaAIuaWX5SanFhcApJBkQhLLMpMzEtOBTIRpjjBTTZCFTPCUIbVYCdUg3WBWmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Node = _t, Category = _t, Attribute = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Node", Int64.Type}, {"Category", type text}, {"Attribute", type text}, {"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Attribute]="Variance" and  [Value]>0 then 1 else 2)
in
    #"Added Custom"

By the way, what did you mean of "I've tryied splitting the data in different tables also but I'm not able to solve it"? If possible, could you please inform me more detailed information(such as your expected output).

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

daledale
Frequent Visitor

Thanks! I've figured it out with your formula. 

az38
Community Champion
Community Champion

hi @daledale 

if i understand you correct try to create a new calculated column

Column = IF(
[Attribute] = "Variance",
IF([Value] < 0,"Better","Worse"),
""
)

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.