cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Abbasi
Frequent Visitor

Measure - ELSE Condition Removes Existing Slicer Filter

One blank value in a row suppresses the entier row. I'm trying to replace blank/ null values from the database with 0 , however, the meausre removes current slicer filters and all records are dispalyed. It show correct number of records if value is not blank.

Ideally, it should be '-' or NA instead of 0. 

Query mode is direct and I have to use null for missing stock at the backend. I have tried to make up following example.

 

Columns on table Visual:
Item.item_name | Stock.Day | Stock.Amount

Item.item_id= Stock.item_id
Item [Shirts, Jackets, Shoes]
Current slicer filter is set to show only Shirts.
However, if value is blank then the fitler fails and 0 is shown for all records instead of current record for Shirts, selected in the slicer.

A null value in Stock.Amount suppresses the entier row. I'm trying to replace blank with 0 but it removes slicer filter

 

amount =
VAR current_value = SELECTEDVALUE('Stock'[amount])
RETURN IF( NOT ISBLANK (current_value) , current_value, 0 )

 

"Show Items with No Data" will show all records but that removes my conditional filtering on other colulmns

3 REPLIES 3
MFelix
Super User
Super User

Hi @Abbasi,

 

The SELECTEDVALUE sintax only returns a single value so when you use a filter with a single value it returns the correct value, however when you have more than one value it returns blanks, in this case 0 because is what you force the measure to do.

 

Since on the table visualization you have the item you should replace the SELECTEDVALUE by SUM that way you get the expected result.

 

amount =
VAR current_value = SUM('Stock'[amount])
RETURN IF( NOT ISBLANK (current_value) , current_value, 0 )

 

Even more you can simplify this metric for one of the options below:

amount =
SUM('Stock'[amount]) + 0


amount =
COALESCE( SUM('Stock'[amount]), 0)

 


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Abbasi
Frequent Visitor

Hi Miguel, 

Thanks for very useful feedback.

Unfortunately, replacing the SELECTEDVALUE with SUM did not resolve the issue in this case. 

Following workaround fixes the issue. Although still not happy with this as I still need to find the exact logic.

I calculated zero instead of explicitely using zero 

VAR zero_value = SELECTEDVALUE  (Stock'[stock_id])

zero_value= zero_value- zero_value;

 

amount =
VAR current_value = SELECTEDVALUE(Stock'[amount])
RETURN IF( NOT ISBLANK (current_value) , current_value, zero_value)

 

If I repalce zero_value =0 then the filter fails.

I'll see If I can further simplify the example and share the file

Regards

Abbasi

Hi @Abbasi ,

 

Can you please share a mockup data or sample of your PBIX file. You can use a onedrive, google drive, we transfer or similar link to upload your files.

If the information is sensitive please share it trough private message.


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.