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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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