cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
frigus
Regular Visitor

How to use SelectedValue when no selection is made

This works while SelectedBranch and SelectedCompany have a value selected from each corresponding slicer. The issue arises when either SelectedBranch or SelectedCompany is selected or none at all. I've tried writing a nested if to cater for it but there has got to be a simplier method.

 

Active = VAR SelectedBranch = SELECTEDVALUE(Companies[cBranch])
VAR SelectedCompany = SELECTEDVALUE(Companies[coid])
Return
CALCULATE(countrows(messages), Messages[mMessageType]<>1, FILTER(ALL(Messages), Messages[coid]=SelectedCompany), FILTER(ALL(Messages), Messages[mRegion]=SelectedBranch), FILTER(ALL(Messages), [mtimeofmsg]<=MIN(DateKey[Date])), FILTER(ALL(Messages), [DateCompleted]>=MIN(DateKey[Date])))
1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Re: How to use SelectedValue when no selection is made

Active =
VAR SelectedBranch = SELECTEDVALUE ( Companies[cBranch] )
VAR SelectedCompany = SELECTEDVALUE ( Companies[coid] )
RETURN
    CALCULATE (
        COUNTROWS ( messages ),
        Messages[mMessageType] <> 1,
        FILTER (
            ALL ( Messages ),
            IF ( ISBLANK ( SelectedCompany ), TRUE (), Messages[coid] = SelectedCompany )
        ),
        FILTER (
            ALL ( Messages ),
            IF ( ISBLANK ( SelectedBranch ), TRUE (), Messages[mRegion] = SelectedBranch )
        ),
        FILTER ( ALL ( Messages ), [mtimeofmsg] <= MIN ( DateKey[Date] ) ),
        FILTER ( ALL ( Messages ), [DateCompleted] >= MIN ( DateKey[Date] ) )
    )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

View solution in original post

3 REPLIES 3
Super User III
Super User III

Re: How to use SelectedValue when no selection is made

Hi @frigus 

I cannot help much cause you don't explain what exactly you would want to do in that case

SELECTEDVALUE( ) has a second parameter that you can use to return a value when there's multiple or no selections.

VAR SelectedBranch = SELECTEDVALUE(Companies[cBranch], ReturnValue when multiple selection here)

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

 

Cheers  Datanaut

Highlighted
frigus
Regular Visitor

Re: How to use SelectedValue when no selection is made

Thanks for your assistance.

 

If there is multiple or no selections, I'd like no filter to be applied at all e.g. in theory, this portion of the dax would be excluded.

 

FILTER(ALL(Messages), Messages[coid]=SelectedCompany)

Thanks.

 

 

Super User III
Super User III

Re: How to use SelectedValue when no selection is made

Active =
VAR SelectedBranch = SELECTEDVALUE ( Companies[cBranch] )
VAR SelectedCompany = SELECTEDVALUE ( Companies[coid] )
RETURN
    CALCULATE (
        COUNTROWS ( messages ),
        Messages[mMessageType] <> 1,
        FILTER (
            ALL ( Messages ),
            IF ( ISBLANK ( SelectedCompany ), TRUE (), Messages[coid] = SelectedCompany )
        ),
        FILTER (
            ALL ( Messages ),
            IF ( ISBLANK ( SelectedBranch ), TRUE (), Messages[mRegion] = SelectedBranch )
        ),
        FILTER ( ALL ( Messages ), [mtimeofmsg] <= MIN ( DateKey[Date] ) ),
        FILTER ( ALL ( Messages ), [DateCompleted] >= MIN ( DateKey[Date] ) )
    )

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

View solution in original post

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors