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
Simple_tuition1
Frequent Visitor

Filter and substracting in rows with dax

Hi,

 

I need your help. I hope somebody can help.. This is the following dummy data. Each sales Person is in multiple countries active and has an overall inventory of products and they are selling extension passes like subscriptions for these products. There are Countries where some sales person is not active or just not active for a certain product type. Therefore they don't posses any values regarding sales and forcast. For example Mary is not active in Canada for City Bike and John ist not active in Italy overall. Therefore there are also no rows of data for these kind of scenarios. 

Data:

ProductSalespersonCountryOverall InventorySold Extension PassForcast Sales Extension Pass
City BikeGinaCanada5400232400
Mountain BikeGinaCanada232328003210
City BikeGinaItaly5400213429
Mountain BikeGinaItaly232310501100
City BikeGinaUSA5400122200
Mountain BikeGinaUSA232321502699
City BikeJohnCanada4323333344
Mountain BikeJohnCanada2133442688
City BikeJohnUSA432333004000
Mountain BikeJohnUSA213373008000
City BikeMaryItaly2321213322
Mountain BikeMaryItaly2312600800
City BikeMaryUSA2321123400
Mountain BikeMaryCanada2312442600
Mountain BikeMaryUSA2312600760
City BikeOverall Canada12044565744
Mountain BikeOverall Canada676836844498
City BikeOverall Italy12044426751
Mountain BikeOverall Italy676816501900
City BikeOverall USA1204435454600
Mountain BikeOverall USA67681005011459

 

The visualization in a matrix looks like this:

 

Simple_tuition1_3-1673973699205.png

 

Now the challenge is that I want to calculate the percentage of the overall amount, which is through Sold / overall inventory. But since Mary is not active in Canada for example, I need to filter those Salesperson, which are not active in each country and then substract for example the overall inventory for City Bike in Canada for Mary (12044-2321). The overall inventory should only consist of active Salespersons in the country. How can I do this with a measure or calculated column in Power BI? If possible I would like to avoid power query since it's already complicated enough regarding transformation in my model.  

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Simple_tuition1 ,

 

I suggest you to try this code to create a measure.

Percentage =
VAR _Namelist =
    CALCULATETABLE (
        VALUES ( 'Table'[Salesperson] ),
        ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Country] ),
        'Table'[Salesperson] <> "Overall"
    )
VAR _NewOverall =
    CALCULATE (
        SUM ( 'Table'[Overall Inventory] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Country] ),
            'Table'[Salesperson] IN _NAMELIST
        )
    )
VAR _Sold =
    CALCULATE ( SUM ( 'Table'[Sold Extension Pass] ) )
RETURN
    DIVIDE ( _Sold, _NewOverall )

Result is as below.

RicoZhou_0-1674025027413.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Simple_tuition1 ,

 

I suggest you to try this code to create a measure.

Percentage =
VAR _Namelist =
    CALCULATETABLE (
        VALUES ( 'Table'[Salesperson] ),
        ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Country] ),
        'Table'[Salesperson] <> "Overall"
    )
VAR _NewOverall =
    CALCULATE (
        SUM ( 'Table'[Overall Inventory] ),
        FILTER (
            ALLEXCEPT ( 'Table', 'Table'[Product], 'Table'[Country] ),
            'Table'[Salesperson] IN _NAMELIST
        )
    )
VAR _Sold =
    CALCULATE ( SUM ( 'Table'[Sold Extension Pass] ) )
RETURN
    DIVIDE ( _Sold, _NewOverall )

Result is as below.

RicoZhou_0-1674025027413.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

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.