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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JustinDoh1
Post Prodigy
Post Prodigy

Need help with multi IF statements

I have attached my PBIX file here.

I am trying to create a column ("Difference to 5-Star condition3") with outputs based on the logic below:

 

------------------------------------------------------------------------------------------------------------

 

If ShortStayScore and LongStayScore are different,

Subtract its total (ShortStayScore + LongStayScore) from 1456 -->  (meaning:  1456 – ((ShortStayScore + LongStayScore)),

If the value becomes negative, put blank.

 

OR

 

If ShortStayScore and LongStayScore are same (meaning ShortStayScore = ‘Not Reported’),

Subtract LongStayScore from 736 -->  (meaning: 736 – (LongStayScore)),

If the value becomes negative, put blank.

------------------------------------------------------------------------------------------------------------

 

Here is examples:

I only illustrated 6 examples here:

JustinDoh1_0-1749247077883.png

 

Thanks for help.

 

1 ACCEPTED SOLUTION

Hi @JustinDoh1 

 

Please try this:

Difference to 5-Star condition3 = 
VAR _ShortStayScore = tblSLTC_FSPI[ShortStayScore]
VAR _LongStayScore = tblSLTC_FSPI[LongStayScore]
VAR _ShortLongScore = _ShortStayScore + _LongStayScore
VAR _Diff1 = 1456 - _ShortLongScore
VAR _Diff2 = 736 - _LongStayScore
RETURN
    SWITCH (
        TRUE (),
        _ShortStayScore <> _LongStayScore, MAX ( _Diff1, BLANK () ),   --blank is bigger than negative
        tblSLTC_FSPI[ShortStayLogic] = "Not Reported", MAX ( _Diff2, BLANK () )   --blank is bigger than negative
    )

danextian_0-1749467940131.png

 

@burakkaragoz Let us please not rely too much on AI and validate the solutions we provide.  ShortStayScore and LongStayScore are both numbers so comparing them with text in variable BothScoresReported will return an error. 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

4 REPLIES 4
v-ssriganesh
Community Support
Community Support

Hi @JustinDoh1,
Thank you for reaching out to the Microsoft fabric community forum.

I have reproduced your scenario in Power BI Desktop and successfully achieved the expected output as per your requirements.

For your reference, I’m attaching the .pbix file containing the solution. You can download it and review the setup to apply it to your report.


If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

JustinDoh1
Post Prodigy
Post Prodigy

@burakkaragoz Thank you so much for your help.

I tried creating a column, and got this bottom message:

JustinDoh1_0-1749431377556.png

 

Hi @JustinDoh1 

 

Please try this:

Difference to 5-Star condition3 = 
VAR _ShortStayScore = tblSLTC_FSPI[ShortStayScore]
VAR _LongStayScore = tblSLTC_FSPI[LongStayScore]
VAR _ShortLongScore = _ShortStayScore + _LongStayScore
VAR _Diff1 = 1456 - _ShortLongScore
VAR _Diff2 = 736 - _LongStayScore
RETURN
    SWITCH (
        TRUE (),
        _ShortStayScore <> _LongStayScore, MAX ( _Diff1, BLANK () ),   --blank is bigger than negative
        tblSLTC_FSPI[ShortStayLogic] = "Not Reported", MAX ( _Diff2, BLANK () )   --blank is bigger than negative
    )

danextian_0-1749467940131.png

 

@burakkaragoz Let us please not rely too much on AI and validate the solutions we provide.  ShortStayScore and LongStayScore are both numbers so comparing them with text in variable BothScoresReported will return an error. 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

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


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
burakkaragoz
Community Champion
Community Champion

Hi @JustinDoh1 ,

Great explanation and thanks for providing clear logic and examples! You can achieve this in Power BI using a DAX calculated column with nested IF statements to handle both scenarios.

Here’s the DAX you can use:

 
Difference to 5-Star condition3 = 
VAR ShortStay = [ShortStayScore]
VAR LongStay = [LongStayScore]
VAR BothScoresReported = 
    AND(
        ShortStay <> "Not Reported",
        LongStay <> "Not Reported"
    )
VAR BothScoresSame = ShortStay = LongStay

// If both scores are reported and different, use the first logic
RETURN
IF(
    BothScoresReported && NOT BothScoresSame,
    VAR Diff = 1456 - (ShortStay + LongStay)
    RETURN IF(Diff < 0, BLANK(), Diff),
    // If both scores are the same (or ShortStayScore = 'Not Reported'), use the second logic
    IF(
        LongStay <> "Not Reported",
        VAR Diff2 = 736 - LongStay
        RETURN IF(Diff2 < 0, BLANK(), Diff2),
        BLANK()
    )
)

A few extra tips:

  • Make sure that “Not Reported” is treated as a text value (not a number). If your data is numeric with blanks for “Not Reported”, use ISBLANK([ShortStayScore]) or ISBLANK([LongStayScore]) instead.
  • Adjust the column names as needed to match your data model exactly.
  • If you want to display the word "BLANK" instead of a blank value, you can replace BLANK() with "BLANK" in the IF statements.

Let me know if you need help adjusting this logic for your specific dataset, or if you want to handle more scenarios!

Happy to help further if needed!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.