cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
andrehawari
Helper II
Helper II

Measure to display value only if "All" is selected, otherwise return blank

Hi, I need to create a measure that have the opposite function in this links

 

https://community.powerbi.com/t5/Desktop/Visualisations-blank-until-something-selected-in-a-slicer/t...

 

 

Basically I want to make the the value is blank when certain value is selected, but it display value only if all is selected

 

Please the find the image below,

When Category is Selected,  and SubCategory=All, the Value2 is displayed

 

1.png

 

However, if ANY of the SubCategory is selected, I want to make the Value2 is BLANK

2.png.



My idea was creating a measure like this (below is just pseudo code)

 

Value2Measure= 

var parameter=selectedvalue(Table[SubCategory]

return 

IF(parameter=  something All selected , sum(value2), else if any of the value is selected, blank())

 

Any idea would be really appreaciated, Thanks !

Andre

1 ACCEPTED SOLUTION
sokg
Solution Supplier
Solution Supplier

Please, try this measure for value2

 

SumValue2 =
VAR NumberFilterCategory =
    COUNTROWS ( VALUES ( TestData[CATEGORY] ) )
VAR NumberFilterSubCategory =
    CALCULATE (
        COUNTROWS ( VALUES ( TestData[SUBCATEGORY] ) );
        ALLEXCEPT ( TestData; TestData[SUBCATEGORY] )
    )
RETURN
    IF (
        NumberFilterCategory <> NumberFilterSubCategory;
        SUM ( TestData[VALUE2] );
        BLANK ()
    )

 

I have these results

Capture2.JPG  Capture.JPG

 

 

my test data was the pic below

Capture3.JPG

 

 

Is this work for you????

View solution in original post

3 REPLIES 3
sokg
Solution Supplier
Solution Supplier

Please, try this measure for value2

 

SumValue2 =
VAR NumberFilterCategory =
    COUNTROWS ( VALUES ( TestData[CATEGORY] ) )
VAR NumberFilterSubCategory =
    CALCULATE (
        COUNTROWS ( VALUES ( TestData[SUBCATEGORY] ) );
        ALLEXCEPT ( TestData; TestData[SUBCATEGORY] )
    )
RETURN
    IF (
        NumberFilterCategory <> NumberFilterSubCategory;
        SUM ( TestData[VALUE2] );
        BLANK ()
    )

 

I have these results

Capture2.JPG  Capture.JPG

 

 

my test data was the pic below

Capture3.JPG

 

 

Is this work for you????

Thanks A lot !

I also getting another approach, but it take 2 measures instead of 1

 

slicerallselected =


var totalslicervalue = calculate(DISTINCTCOUNT(Sheet1[SubCategory]),ALL(Sheet1[SubCategory]))
var countselectedvalue= calculate(DISTINCTCOUNT(Sheet1[SubCategory]),ALLSELECTED(Sheet1[SubCategory]))

return

IF(totalslicervalue=countselectedvalue,1,0)

 

 

 

Value2Measure = switch([slicerallselected],1,sum(Sheet1[Value2]),0,blank())

sokg
Solution Supplier
Solution Supplier

you can test both to see what is works better with your data (performance issues).

 

you can see this video to check how both measures perform with you data

 

https://www.sqlbi.com/tv/my-power-bi-report-is-slow-what-should-i-do/

 

Italians here do great job!!!

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors