reporting-servicespower-bi-report-serverssrs-expression

How come SSRS Contains or Like Expression not working?


I'm using MS Power BI Report Builder, and I'm having trouble getting the "Contain" function to work with an IF statement. I was wondering if anyone could help me figure out what's wrong with my expression. It's been giving me some headaches, and I could really use some assistance.

=iif(First(Fields!test.Value, "Test"). Contains("Yes - Axon"), "Yes", "No")
=iif(First(Fields!test.Value, "Test"). Like("Yes - Axon"), "Yes", "No")

The "Contains" function, but it's acting all wonky. No matter what, it keeps giving me "No" as the result, even when the "test" column clearly contains "Yes - Axon". Can anyone take a look at the values below and help me figure out what's going on? enter image description here

enter image description here Thank you So much


Solution

  • Your expression are using FIRST() so they will only check the first value test.Value in the Test data set. If you add a table to your report and drag the test field onto it, then set your expression without the first() in another second column, it should work.

    So the expression just needs to look like this.

    =IIF(
         Fields!test.Value.Contains("Yes - Axon"), 
         "Yes", 
         "No"
        )
    

    There is no need to specify the scope of the expression as it will use the current context (in this case the current row)


    Quick demo


    I recreated your sample data with the following dataset query

    DECLARE @t TABLE (test nvarchar(256))
    
    INSERT INTO @t VALUES 
    ('Yes - LR Appliances'),
    ('Yes - LR Appliances'),
    ('Yes - LR Appliances'),
    ('Yes - LR Appliances, Yes - Axon'),
    ('Yes - LR Appliances'),
    ('Yes - LR Appliances, Yes - Axon'),
    ('Yes - Customer VMs'),
    ('Yes - LR Appliances, Yes - Axon, Yes - LR Cloud'),
    ('Yes - LR Appliances, Yes - Axon, Yes - LR Cloud, Yes - Customer VMs'),
    ('Yes - LR Appliances, Yes - Axon, Yes - LR Cloud, Yes - Customer VMs'),
    ('Yes - LR Appliances, Yes - Axon, Yes - LR Cloud'),
    ('Yes - LR Appliances'),
    ('Yes - LR Appliances')
    
    SELECT * FROM @t
    

    I created a blank report, added the above as a dataset query then added a table.

    In the first column I simple used the test field.

    In the 2nd column I set the expression to the expression I mentioned above.

    =IIF(
         Fields!test.Value.Contains("Yes - Axon"), 
         "Yes", 
         "No"
        )
    

    When I run the report, I get the results I would expect...

    enter image description here

    Here's a short 30 second GIF I recorded whilst I created this report. If you can't see it clearly, right-click the gif and open in new window, then you can maximise to see it clearly.

    enter image description here