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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sathvika
New Member

Am getting cant compare the text and integer values in calculated column.

Hello powerbi Experts,

 

actuvally i have 2 fields one is wholesaler and rank ,wholesaler is text type data and rank is number so coming to requirement

wholesaler is the slicer when user will select the one single value in the slicer according to selection the rank data should be displayed ,when user will select more than a single selection the rank should nt be display. according to that i have written dax function like this.

 

IF(SELECTEDVALUE(Sheet1[whole saler])>=1,Sheet1[Rank],""),
 
but i have changed the wholesaler data type as a wholenumber still am getting same error,can please give some inputs on that do needful.
Thank you
 
Rega
1 REPLY 1
dm-p
Super User
Super User

Hi @sathvika, and welcome to the forums!

Just to let you know for future questions, something along this line is better asked in the DAX or Desktop forums. These two forums have a lot of people able to answert these kinds of questions within a short time of you posting.

The Developer forum relates to extending Power BI via code and doesn't get a lot of traffic so you might have to wait longer for someone to find your question, or even pick it up.

I want to try and help get you moving with this challenge, but I think you'll have some follow-up questions that might be better being posted in those forums above.

There are a couple of issues here that are giving you trouble:

  • If you're creating a calculated column, they can't have what are called variant data types - they need to be one or the other. Your code is trying to return Rank which is a number, and an empty text value if your conditions aren't met. In the case of a number you might want to return BLANK() instead, which basically means empty.

    I would re-write your column this way:

    IF(SELECTEDVALUE(Sheet1[whole saler])>=1,Sheet1[Rank], BLANK())

  • If you're trying to have this work off a slicer, then a calculated column will not work. Calculated columns are computed when the model is refreshed and then do not change.

    If you want something to respond to a slicer (i.e. using something like SELECTEDVALUE to determine state, then this will need to be a measure instead, as these respond to dynamic context in your report.

    Columns will not recalculate based on a slicer value or dynamic filter context.

    With a measure, you cannot refer to a column explicitly, as Power BI will aggregate values, even if you are showing every single row, so you will need to specify the aggregate value to use when comparing. For your example, my measure looks as follows:

    Test Measure =
        IF (
            SELECTEDVALUE(Sheet1[whole saler]) >= 1,
            MAX(Sheet1[Rank]),
            BLANK()
        )

    I have used a MAX function to give the IF statement something to evaluate but you will need to look at your data to determine the best way to evaluate. There is not enough information in your question about your data model for me to provide a targeted answer for you.
     

I have attached a simple workbook withhow I perceive your solution to be with some simple data and have added a slicer and a Test Measure for you to have a look at. I would suggest that you take a look at this, and see if you can apply it to your report.

Once you have a grasp of this and know what your next steps might be in your challenge, post a follow-up request in either the DAX or Desktop forums. It will help a lot if you are able to share some sample data and details about your model - have a read of this post to learn about the best way to get help with your question and you'll get the best possible help in no time at all 😉

I hope this helps you out a little bit, and good luck!

Daniel





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

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




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.