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
jday
Helper I
Helper I

If Slicer is selected then do?

Hello, 

 

Essentially I am trying to create an if statement based on a slicers selected value.  Below you can find a mock up of my data.  

IDStartEndNew
1RedBlue 1
2RedBlue 1
3RedBlue 1
4RedBlue 1
5RedBlue 0
6RedBlue 0

 

Ideally I want a slicer for the New column and I want the syntax to read
IF(NEW = 1, 
(VAR
Rankingcontext = Values(Table1[Start])
Return
CALCULATE(count(Table1[ID]),
TOPN(2,
ALL(table1[Start]),
Count(Table1[ID])),
Rankingcontext )),
(VAR 
Rankingcontext = Values(Table1[end])
Return
CALCULATE(count(Table1[ID]), 
TOPN(2, 
ALL(table1[end]),
Count(Table1[ID])),
Rankingcontext )))


1 ACCEPTED SOLUTION

Hi @jday,

After research, you can follow the steps.

1. Create a slicer including [New] column.

2. Create two measures using the formular.

END_Start =
IF (
    SELECTEDVALUE ( Table1[New] ) = 1,
    FIRSTNONBLANK ( Table1[Start], Table1[Start] ),
    FIRSTNONBLANK ( Table1[End], Table1[End] )
)

ID COUNT =
IF (
    ISFILTERED ( Table1[New] ),
    COUNT ( Table1[End] ),
    CALCULATE ( COUNT ( Table1[Start] ), FILTER ( Table1, Table1[New] <> 1 ) )
)


Then, create a table visual, select the two measures, you will get expected result as follows.

when 1 is selectedwhen 1 is selectedwhen 1 is not selectedwhen 1 is not selected

You can download the .pbix(attachment) for checking more details.

Best Regards,
Angelia

View solution in original post

3 REPLIES 3
v-huizhn-msft
Employee
Employee

Hi @jday,

It's hard to understand your requirement, what result do you want to return? Could you please clear up your requirement, so that we can help you in details.

Thanks,
Angelia

If a slicer is applied for "New" and 1 is selected then I want the a table to show 

END       ID COUNT 

Red       4


If 1 is not selected then I want the results to be 
End       ID COUNT 

Blue      2  

Hi @jday,

After research, you can follow the steps.

1. Create a slicer including [New] column.

2. Create two measures using the formular.

END_Start =
IF (
    SELECTEDVALUE ( Table1[New] ) = 1,
    FIRSTNONBLANK ( Table1[Start], Table1[Start] ),
    FIRSTNONBLANK ( Table1[End], Table1[End] )
)

ID COUNT =
IF (
    ISFILTERED ( Table1[New] ),
    COUNT ( Table1[End] ),
    CALCULATE ( COUNT ( Table1[Start] ), FILTER ( Table1, Table1[New] <> 1 ) )
)


Then, create a table visual, select the two measures, you will get expected result as follows.

when 1 is selectedwhen 1 is selectedwhen 1 is not selectedwhen 1 is not selected

You can download the .pbix(attachment) for checking more details.

Best Regards,
Angelia

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.