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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Jameli
Frequent Visitor

Dax help needed with outlier case for all selected groups (ALLSELECTED)

I have a case where I would have to calculate a % of total of sales for 2 selected groups but only one of them is in visual.

Here's my data in picture

So I would like to first select Groups B and C, then select products only from C (Green and Yellow grapes). Then I would like to see the percentage of sales Green and Yellow Grapes contributed to Total sales of Groups B and C.

So Desired outcome would be for Green grapes (30 / 70) ~43% and for Yellow Grapes (10/70) ~14%.

I tried using ALLSELECTED but it does not work when I only have Group C products selected in visual. 

This video got me pretty close, but it's not working since there are only Group C products in visual: 

DAX Fridays! #118:  Get selected or multiple values from slicers using DAX


Any ideas is this even possible or how to proceed?

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your dataset looks like, but one of ways to create a solution is to have dimension table for Group, like below. In this case, Group slicer won't be influenced by the product selection.

 

Picture2.png

 

Percent of sales from selected groups: = 
VAR _sales = [Sales measure:]
VAR _selectedgroup =
    VALUES ( 'Group'[Group] )
VAR _grouptotal =
    CALCULATE (
        [Sales measure:],
        FILTER ( ALL ( Data ), Data[Group] IN _selectedgroup )
    )
RETURN
    DIVIDE ( _sales, _grouptotal )

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

3 REPLIES 3
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your dataset looks like, but one of ways to create a solution is to have dimension table for Group, like below. In this case, Group slicer won't be influenced by the product selection.

 

Picture2.png

 

Percent of sales from selected groups: = 
VAR _sales = [Sales measure:]
VAR _selectedgroup =
    VALUES ( 'Group'[Group] )
VAR _grouptotal =
    CALCULATE (
        [Sales measure:],
        FILTER ( ALL ( Data ), Data[Group] IN _selectedgroup )
    )
RETURN
    DIVIDE ( _sales, _grouptotal )

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.

Thanks, this is how I would like it to work.

This unfortunately doesn't work straight away in my case since the dimension table is not joined by Group -field but another field. I could solve this by creating a another separate dimension which is joined by the Group field, but I'll have to think if I want to create a separate solution for this.

Maybe creating an inactive relation by group and using it in your solution with USERRELATIONSHIP would work as well.

johnt75
Super User
Super User

Try

% sales of selected group =
VAR currentSales = [Sales]
VAR selectedGroupSales =
    CALCULATE ( [Sales], ALLEXCEPT ( 'Product', 'Product'[Group] ) )
RETURN
    DIVIDE ( currentSales, selectedGroupSales )

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.