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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
praveen_k
Helper I
Helper I

IF to select a column value

I am trying to use a IF statement to select a column. I have a measured column which calculates percentage change. When the percentage change (measure column) is greater than 0, ID column should be selected and viewed on report. eg- id total month measure 23 65 2 0 23 85 3 0.3 5 6 2 0 5 5 3 -0.16 2 10 2 0 2 11 3 0.1 When the measure column is -0.16, ID = 5 need to be displayed on the report.
10 REPLIES 10
v-caliao-msft
Employee
Employee

Hi Praveen_k,

 

According to your description, you need to display the ID which have measure value >0, right?

 

If that is the case, you can create a calculated column to display if the current have measure value >0 or not. I have tested it on my local environment, here is the sample DAX expression below for you reference.
Check = IF(IFfunction[measure]<0,1,0)
Sciler = IF(CALCULATE(SUM(IFfunction[Check]),ALLEXCEPT(IFfunction,IFfunction[id]))>0,"<0",">0")
Capture.PNGCapture1.PNG

Regards,

Charlie Liao

praveen_k
Helper I
Helper I

Book1 - Excel_2016-05-16 10-30-34.jpg

@praveen_k I'm assuming you want to keep the measure column. And my other assumption is that you want to keep the measure if the value is greater than or equal to zero, and everything that is under should be the ID. Here is a calc column that will work for what you are asking. If this is not accurate, please clarify the discription.

 

Value = IF('table'[measure] >= 0, 'table'[measure], 'table'[id])

 


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

Hi @Seth_C_Bauer

Just a quick note on your formula regarding best practise

we should avoid putting the Table name next to the measure
ref: top 5 best practise tips

@praveen_kAs Eno suggested your calc column should work, but I'd suggest appending the result with something so that the reader knows that the value returned is either the Id or the result of a mesaure

-- ------------------------------ --
Please mark solutions as complete when your question has been answered
-- ------------------------------ --

@Neuro81 Thanks for pointing that out. I just used the quick defaults on this one, but I typically have been referencing my calculated columns the same as normal columns (with table name), and measures as the only outlier (no table name). Must have mis-read this in my reading.


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

@Seth_C_Bauer @Neuro81 Thanks for your inputs. 

 

This is the actual measure calculation. 

 

Power BI Desktop_2016-05-17 07-54-32.jpg

 

I tried using your expression and this is what I get - 

 

Power BI Desktop_2016-05-17 07-58-27.jpg

 

On the reports, I would like to view the ID column when when measure2 > 0 and Null/Blank when measure2 < 0. 

 

Hope this clarifies my original question. 

Correction to the above reply - 

 

On the reports, I would like to view the ID column when when measure1 > 0 and Null/Blank when measure1 < 0. 

@praveen_k This initial code is for a Calculated Column.

 

This should work for a measure: 

AsMeasure = IF([measure1] >= 0, VALUES('table'[id]), BLANK())


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

Temp.jpg 

Error Message:

MdxScript(Model) (1, 51) Calculation error in measure 'Table'[Measure2]: A table of multiple values was supplied where a single value was expected.

 

 

@Seth_C_Bauer @Neuro81 

 

I tried to choose table and card visualizations on the report to display measure2 value, and I see this error.

Am I doign somehing wrong ?

@praveen_k If you are going to filter it down to see the individual rows, you can use the original calculation as a calculated column. The slicer works with that.


Looking for more Power BI tips, tricks & tools? Check out PowerBI.tips the site I co-own with Mike Carlo. Also, if you are near SE WI? Join our PUG Milwaukee Brew City PUG

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors