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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
BrianNeedsHelp
Helper III
Helper III

Return Items that have Neither Item Selected

A DAX Puzzler:  I have an inventory problem I'm trying to solve.  Each location has inventory in a table TableQOHRemoveZeros.   If I select the items in the slicer, I want it to return locations that have NEITHER item.  E.g.  if I select iPhone 12 and iPhone 13 in the Slicer, the only location that should return is Location 114 Plum Lane.  

DISTINCT(TableQOHRemoveZeros[Device Name Short])

 

I thought that I could query this table after the items were selected against all of the locations using Except, but I don't think it's possible to query a table created by slicer selection. 

LocationsWithoutSelectedDevices2 = VAR SelectedLocations= ALLSELECTED(DisDeviceNameShort[Device Name Short]) VAR AllLocations = All('Current Hierarchy'[Sales Code]) Var ExcludeSelectedLocation = EXCEPT(SelectedLocations,AllLocations) Return (ExcludeSelectedLocation)

 

Error:"A table with multiple values was returned when a single value expected" A real doozy.   Any way to achieve this?  I think it would have huge benefit to others as well and would greatly streamline a process like this.  

Sales CodeLocationDevice Name Short
111123 Main StiPhone 12
111123 Main StIphone 16
111123 Main StIphone 11
112111 Elm StIphone 10
112111 Elm StIphone 13 
112111 Elm StiPhone 14
114800 Plum lniPhone 15
114800 Plum lniPhone 16
114800 Plum lniPhone 17

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1734926100656.png

 

 

Jihwan_Kim_0-1734926069514.png

 

Deviace Name short: = 
VAR _slicerselect =
    VALUES ( Slicer[Device Name Short] )
VAR _salescodelist =
    SUMMARIZE (
        FILTER (
            ALL ( TableQOHRemoveZeros ),
            TableQOHRemoveZeros[Device Name Short] IN _slicerselect
        ),
        TableQOHRemoveZeros[Sales Code]
    )
VAR _others =
    EXCEPT (
        SUMMARIZE ( ALL ( TableQOHRemoveZeros ), TableQOHRemoveZeros[Sales Code] ),
        _salescodelist
    )
RETURN
    CALCULATE (
        MAX ( TableQOHRemoveZeros[Device Name Short] ),
        FILTER ( TableQOHRemoveZeros, TableQOHRemoveZeros[Sales Code] IN _others )
    )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

6 REPLIES 6
Kedar_Pande
Community Champion
Community Champion

@BrianNeedsHelp 

Measure:

LocationsWithoutSelectedDevices =
VAR SelectedDevices = ALLSELECTED(TableQOHRemoveZeros[Device Name Short])
VAR LocationsWithSelectedDevices =
SUMMARIZE(
FILTER(
TableQOHRemoveZeros,
TableQOHRemoveZeros[Device Name Short] IN SelectedDevices
),
TableQOHRemoveZeros[Sales Code]
)
VAR AllLocations = VALUES(TableQOHRemoveZeros[Sales Code])
VAR LocationsWithoutDevices =
EXCEPT(
AllLocations,
LocationsWithSelectedDevices
)
RETURN
IF(
SELECTEDVALUE(TableQOHRemoveZeros[Sales Code]) IN LocationsWithoutDevices,
1,
0
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1734926100656.png

 

 

Jihwan_Kim_0-1734926069514.png

 

Deviace Name short: = 
VAR _slicerselect =
    VALUES ( Slicer[Device Name Short] )
VAR _salescodelist =
    SUMMARIZE (
        FILTER (
            ALL ( TableQOHRemoveZeros ),
            TableQOHRemoveZeros[Device Name Short] IN _slicerselect
        ),
        TableQOHRemoveZeros[Sales Code]
    )
VAR _others =
    EXCEPT (
        SUMMARIZE ( ALL ( TableQOHRemoveZeros ), TableQOHRemoveZeros[Sales Code] ),
        _salescodelist
    )
RETURN
    CALCULATE (
        MAX ( TableQOHRemoveZeros[Device Name Short] ),
        FILTER ( TableQOHRemoveZeros, TableQOHRemoveZeros[Sales Code] IN _others )
    )

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

This is amazing!  Would it be possible for you to tweak it to only show the location and not all the device names?  A distinct location returned for locations that have neither device.  So it would return like this:  Sales Code   Location
                                      114               800 Plum Lane 

Hi,

Thank you for your message, and one of ways is to put the measure to the Filter Pane -> Filters on this visual area, like the below image.
Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1734930221740.png

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

@Kedar_Pande @Jihwan_Kim    I combined several table columns  together using Summarize to get into one table.   I'm having issues getting everything to display properly.  So I went back to try and use this code with the original tables, and I'm getting error "expression refers to multiple columns.Multiple columns cannot be converted to a scalar value."  Not sure I formatted this correctly, but the only wat it would allow me to use other tables was to type RELATEDTABLE.     

LocationsWithoutSelectedDevices1 = 

VAR _slicerselect =
    VALUES ( DisDeviceName[Device Name] )
VAR _salescodelist =
    SUMMARIZE 
       (FILTER (
            ALL ('Location'),
           Filter(RELATEDTABLE( 'Item Code'),'Item Code'[Device Name] IN _slicerselect) && Filter(RELATEDTABLE('Device Inventory On Hand'),'Device Inventory On Hand'[Device Inventory QOH])<>0 ),
          Location[Sales Code]      
    )
VAR _others =
    EXCEPT (
        SUMMARIZE ( ALL ( Location ), Location[Sales Code] ),
        _salescodelist
    )
RETURN
    CALCULATE(
        MAX (Location[Location] ),
        FILTER ( Location, Location[Sales Code] IN _others )
    )

Please help adapt code to use with separate tables.   

You are amazing @Jihwan_Kim !   Thank you so much-This is so awesome!  

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.