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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

IF STATMENT SHANIGANS

Hi there, first time poster, im hoping someone can tell me whats going on here.

Ok so in my project i am using a measurment with this code 

========================================

var TestResultCount = COUNTROWS(TestConducted)
var FailRowCount = (COUNTROWS(aTable))
return

IF(TestResultCount >0,if(FailRowCount < 1,"Yes","No"),"NA")
========================================
so the output im expecting is
If there are tests, return yes, or No if the test succeeded of not. Or Return NA if there are no tests.

 

In the specific data set i am using there are no Fail cases, and 50% success and 50% NA

the issue i have is the above logic runs without error returning 100% NA

However if the line is changed to 
IF(TestResultCount >0,if(True()< 1,"Yes","No"),"NA")
i get my expected results with 50% of the results returning "Yes" and 50% returning "NA"

I believe this is because aTable is blank, however using Isblank(aTable ) 
EG. IF(TestResultCount >0,if(Isblank(aTable ),"Yes","No"),"NA")
Also doesnt work. with all results still returning NA.

 

I believe that when the success result of the first if statement hits an error, it instead of stopping just goes to NA. 

Please let me know your thoughts and opinions on why this is happening. 
Below is the full code
=======================================================

Test_Flow status Minus Below peak level =

var TestConducted = FILTER('Hourly Telem Data',
AND('Hourly Telem Data'[Flow status Minus Below peak level] <> "",
'Hourly Telem Data'[SiteRef] == [SiteRef]
))

var aTable = FILTER(TestConducted,
AND('Hourly Telem Data'[Flow status Minus Below peak level] == "Fail",
'Hourly Telem Data'[SiteRef] == [SiteRef]
))

var TestResultCount = COUNTROWS(TestConducted)
var FailRowCount = COUNTROWS(aTable)

return
if (TestResultCount >0,
if(FailRowCount < 1,"Yes","No"
),"NA")

========================================================

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Ok the issue is solved. 

Test_Flow status Minus Below peak level =

Changing 
VAR aTable =
FILTER (
TestConducted ,
AND (
'Hourly Telem Data'[Flow status Minus Below peak level] == "Fail",
'Hourly Telem Data'[SiteRef] = [SiteRef]
)
)

TO
VAR aTable =
FILTER (
'Hourly Telem Data',
AND (
'Hourly Telem Data'[Flow status Minus Below peak level] == "Fail",
'Hourly Telem Data'[SiteRef] = [SiteRef]
)
)

i think this may have something to do with how filtering sub tables work inside the if statment. All variables have their expected results outside the if statment, but when they are both used, the second variable is set to blank.

If you have an issue like this in future try to not filter a sub table if possible draw from the original table.
 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Ok the issue is solved. 

Test_Flow status Minus Below peak level =

Changing 
VAR aTable =
FILTER (
TestConducted ,
AND (
'Hourly Telem Data'[Flow status Minus Below peak level] == "Fail",
'Hourly Telem Data'[SiteRef] = [SiteRef]
)
)

TO
VAR aTable =
FILTER (
'Hourly Telem Data',
AND (
'Hourly Telem Data'[Flow status Minus Below peak level] == "Fail",
'Hourly Telem Data'[SiteRef] = [SiteRef]
)
)

i think this may have something to do with how filtering sub tables work inside the if statment. All variables have their expected results outside the if statment, but when they are both used, the second variable is set to blank.

If you have an issue like this in future try to not filter a sub table if possible draw from the original table.
 
amitchandak
Super User
Super User

@Anonymous ,Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
AlB
Super User
Super User

Hi @Anonymous 

Is this a measure or a calculated column ? If the former, how/where are you using it?

What is this? What are you trying to do?

       'Hourly Telem Data'[SiteRef] == [SiteRef]

It would help if you show a sample of the relevant tables

Try this for the time being:

Test_Flow status Minus Below peak level =
VAR TestConducted =
    FILTER (
        'Hourly Telem Data',
        AND (
            'Hourly Telem Data'[Flow status Minus Below peak level] <> "",
            'Hourly Telem Data'[SiteRef] = EARLIER ( 'Hourly Telem Data'[SiteRef] )
        )
    )
VAR aTable =
    FILTER (
        TestConducted,
        AND (
            'Hourly Telem Data'[Flow status Minus Below peak level] == "Fail",
            'Hourly Telem Data'[SiteRef] = EARLIER ( 'Hourly Telem Data'[SiteRef] )
        )
    )
VAR TestResultCount =
    COUNTROWS ( TestConducted )
VAR FailRowCount =
    COUNTROWS ( aTable )
RETURN
    IF ( TestResultCount > 0, IF ( FailRowCount < 1, "Yes", "No" ), "NA" )

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

 

SU18_powerbi_badge

Anonymous
Not applicable

the code i have constructed is for a measure.

The measure is meant to look over the "Flow status minus below peak level" field in the "Hourly Telem Data" .If the field is not entirely blank, state wheather or not there is one or more "Fail"s in that data set


The measure is set in a different table than "Hourly Telem Data", one which has a unque set of SIte refs, as well as all the other test Measures i need.

'Hourly Telem Data'[SiteRef] == [SiteRef]
This is used to connect the hourly Telem data set to the current tables SiteRef Key

as there is a one to many relationship between the current table and the Hourly Telem Data table.

I tried your solution, power bi wouldn't except the use of the Earlier function stating incorrect paramater type. 

Gabriel_Walkman
Continued Contributor
Continued Contributor

@Anonymous if you test just your TestResultCount, does it produce the correct number?

 

Also, please refrain from topics in all capital 🙂

Anonymous
Not applicable

Yeah TestResultCount does. 

Sure thing.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.