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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mmills2018
Helper IV
Helper IV

If/or statement with slicers

Hello,

I have the below meaure in power bi,  for my "return" i want to set it up so if i to (PoC[PoC (USA Only)]) it will give me my PoC calc (cta_rawpoc) and if i filter to ( Gender[Gender] ) it will give me my gender calc (cta_raw).  any ideas how i can use an if/or statement with slicers?

 

test2 = VAR filtered =
//table with public filter conditions
FILTER (
'Talent Snapshot',
[Potential] <> ""
)
VAR cta_add =
//cta with additional filter
SUMX ( FILTER (filtered,[Gender] IN VALUES ( Gender[Gender] ) ), [Count Total Associates (PME)] )
VAR cta_poc =SUMX ( FILTER (filtered,[Race/Ethnicity] IN VALUES ( PoC[PoC (USA Only)] ) ), 'Talent Snapshot'[PME USA Headcount] )
VAR cta_raw =
//cta wiht raw filter
SUMX ( filtered, [Count Total Associates (PME)] )
VAR cta_rawpoc = SUMX(filtered, [Sum USA headcount])
VAR _flagG = ISFILTERED(Gender[Gender])
VAR _flagpoc = ISFILTERED(PoC[PoC (USA Only)])
VAR _round =
ROUND (
IF (
_flagG,
MAX ( 0, DIVIDE ( cta_add, cta_raw ) ),
DIVIDE ( cta_raw, SUM ( [Count Total Associates (PME)] ) )
),
2
) * 100
VAR _roundpoc = round(IF(_flagpoc, MAX ( 0, DIVIDE ( cta_poc, cta_rawpoc ) ),
DIVIDE ( cta_rawpoc, SUM ( 'Talent Snapshot'[PME USA Headcount] ) )),2)*100
VAR _fixed =
MAX ( 0, VALUE ( FIXED ( IF ( _flagG, cta_add, cta_raw ), 0 ) ) )
VAR _fixedpoc =
MAX ( 0, VALUE ( FIXED ( IF ( _flagpoc, cta_poc, cta_rawpoc ), 0 ) ) )
RETURN
1 ACCEPTED SOLUTION
v-jayw-msft
Community Support
Community Support

Hi @mmills2018 ,

 

If I understand you correctly, you could use ISFILTERED() function with SWITCH() or IF() function.

For example:

SWITCH(TRUE(),ISFILTERED(slicer1),measure1,ISFILTERED(slicer2),measure2,measure3).

Measure = 
var _a = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER('Table','Table'[Company]=SELECTEDVALUE('Table'[Company])&&'Table'[Potential]<>BLANK()))
var _b = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER('Table','Table'[Company]=SELECTEDVALUE('Table'[Company])))
return
_a/_b

Measure 2 = 
var _a = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER('Table','Table'[Company]=SELECTEDVALUE('Table'[Company])&&'Table'[Potential]<>BLANK()))
var _b = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER(ALL('Table'),'Table'[Company]=SELECTEDVALUE('Table'[Company])&&'Table'[Potential]<>BLANK()))
return
_a/_b

5.PNG

6.PNG

The same for the POC slicer.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

7 REPLIES 7
v-jayw-msft
Community Support
Community Support

Hi @mmills2018 ,

 

If I understand you correctly, you could use ISFILTERED() function with SWITCH() or IF() function.

For example:

SWITCH(TRUE(),ISFILTERED(slicer1),measure1,ISFILTERED(slicer2),measure2,measure3).

Measure = 
var _a = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER('Table','Table'[Company]=SELECTEDVALUE('Table'[Company])&&'Table'[Potential]<>BLANK()))
var _b = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER('Table','Table'[Company]=SELECTEDVALUE('Table'[Company])))
return
_a/_b

Measure 2 = 
var _a = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER('Table','Table'[Company]=SELECTEDVALUE('Table'[Company])&&'Table'[Potential]<>BLANK()))
var _b = CALCULATE(DISTINCTCOUNT('Table'[Associate ID]),FILTER(ALL('Table'),'Table'[Company]=SELECTEDVALUE('Table'[Company])&&'Table'[Potential]<>BLANK()))
return
_a/_b

5.PNG

6.PNG

The same for the POC slicer.

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
parry2k
Super User
Super User

@mmills2018 see attached, tweak it as per your need.

 

Check my latest blog post Improve UX: Show Year in Legend When Using Time Intelligence Measures | PeryTUS IT Solutions  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

thanks but my filters are not connected to the data source.  I need an If Poc is filter then XYZ, if gender is filter than XYZ

Hi @parry2k any ideas?

mmills2018
Helper IV
Helper IV

here is sample data:

Associate IDGenderRace/EthnicityPotentialCompany
1FemaleWhitePotentialA
2MaleLatinXPotentialA
3MaleBlackPotentialA
4MaleAsianHigh PotentialA
5MaleWhiteGrow in RoleA
6FemaleWhite A
7MaleBlackPotentialA
8FemaleBlackHigh PotentialA
9FemaleLatinxGrow in RoleB
10FemaleLatinx B
11FemaleAsian B
12FemaleAsianPotentialB
13FemaleAsianPotentialB
14MaleWhiteGrow in RoleB

 

and here is my expected output:

 Associates with Potential
Company A87.5% (7)
Company B66.7% (4)

 

when I filter by Gender and select Female, I want my "Associates with Potential" column to update based on gender values, see below:

Company A28.6% (2)
Company B75% (3)

 

when I filter by PoC and select Asian, Black or Latinx, I want my "Associates with Potential" column to update based on PoC values, below is all PoC but when I select "Asian" in my slicer I would like to see the values for Asian population: 

Company A71.4% (5)
Company B75% (3)

 

I have two slicers(POC with POC(USA Only Values) and Gender with Gender Values, both are not pulling from my data source (I can't for purposes with female and poc calcs).  My measure is set up correctly, i just don't know how to return female values when female is selected or poc value when asian is selected or both, asian females selected.  any ideas?

Hi @parry2k  - did the above help you at all?

parry2k
Super User
Super User

@mmills2018 it will be much easier if you provide sample data and expected output, it is very hard to do reverse engineering of such a long DAX expression without understanding the data and the requirement.

 

Check my latest blog post Improve UX: Show Year in Legend When Using Time Intelligence Measures | PeryTUS IT Solutions  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.