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
Ritaf
Responsive Resident
Responsive Resident

filter table by value wich not a chosen one

Hi,

I have a table with sales data attached, i want to see potential customers to sell them a product (sku) they don't have. potential customer is one who don't have a sku or sales of a specific sku is 0.

i read a article about selected value

https://www.sqlbi.com/articles/using-the-selectedvalue-function-in-dax/

but didnt understand how it helps me.

i hope somebody will assit me,

thanks a lot, Rita

ParentPeriodPeriodCustomerCodeCustomerNameRegionTerritoryClusterCityCustomerStatusSKUSales
2019Jan1000024     מכולת משהSouthיבנהאלי כהןרחובותAx3000
2019Feb1000024     מכולת משהSouthיבנהאלי כהןרחובותAx3950
2019Mar1000024     מכולת משהSouthיבנהאלי כהןרחובותAx5450
2019Apr1000024     מכולת משהSouthיבנהאלי כהןרחובותAx2450
2019Jan1000024     מכולת משהSouthיבנהאלי כהןרחובותAy400
2019Feb1000024     מכולת משהSouthיבנהאלי כהןרחובותAy250
2019Mar1000024     מכולת משהSouthיבנהאלי כהןרחובותAy600
2019Apr1000198     מכולת בניSouthירושליםדוד לויירושליםAx6
2019Jan1000024     מכולת משהNorthחיפהאלי כהןרחובותAz1450
2019Feb1000024     מכולת משהNorthיבנהאלי כהןרחובותHz1750
2019Mar1000024     מכולת משהNorthיבנהאלי כהןרחובותAz2300
2019Apr1000024     מכולת משהNorthיבנהאלי כהןרחובותAy300
2019Jan1000198     מכולת בניNorthירושליםדוד לויירושליםAx20
2019Feb1000198     מכולת בניNorthירושליםדוד לויירושליםBx10
2019Mar1000198     מכולת בניNorthירושליםדוד לויירושליםAx7
2019Apr1000198     מכולת בניNorthירושליםדוד לויירושליםAy10
2 ACCEPTED SOLUTIONS
d_gosbell
Super User
Super User

So the "trick" to doing this would be to create a disconnected table of products with a distinct list of the SKUs. In the code below I have called this table "Products to Sell" and I have called your original table "Table1" and I deleted the relationship that Power BI automatically created between the 2 SKU columns.

 

Then the following measure will return a 1 or a blank against each customer code if they have the selected product from the "Products To Sell" table. Because Power BI automatically hides rows that have blank values if you put just the customer code/ customer name in a table with this measure it will only list customers that have not bought the selected product.

 

Potential Customers = 
var _selectedSKU = ALLSELECTED('Product To Sell'[SKU])
var _selectedSales = ADDCOLUMNS( DISTINCT(Table1[CustomerCode]), "SkuSales" , CALCULATE(sum(Table1[Sales]), TREATAS(_selectedSKU, Table1[SKU])))
var _filteredSales = FILTER(_selectedSales, [SkuSales] = 0)
return COUNTROWS(_filteredSales)

2019-04-PotentialCustomers.gif

View solution in original post

v-juanli-msft
Community Support
Community Support

Hi @Ritaf 

Assume you have "customer table" with "CustomerCode" column and "product table" with "product SKU" column

I can create a crossjoin table (enter this formula in formula bar (Modeling->new table)

this table would show all CustomerCode with all product SKU

crossjoin table = CROSSJOIN('customer table','product table')

13.png

 

Then create another table, this table would show which customer have product sku and their sales is not 0.

generate table =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            Sheet9,
            "sum_value", CALCULATE (
                SUM ( Sheet9[Sales] ),
                ALLEXCEPT ( Sheet9, Sheet9[CustomerCode], Sheet9[SKU] )
            )
        ),
        [sum_value] <> 0
    ),
    Sheet9[CustomerCode],
    Sheet9[SKU]
)

14.png

 

Finally create a new table, this table would show potential as you expected.

final Table = EXCEPT('crossjoin table','generate table')

15.png

Best Regards
Maggie

 

Community Support Team _ Maggie Li
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

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi @Ritaf 

Assume you have "customer table" with "CustomerCode" column and "product table" with "product SKU" column

I can create a crossjoin table (enter this formula in formula bar (Modeling->new table)

this table would show all CustomerCode with all product SKU

crossjoin table = CROSSJOIN('customer table','product table')

13.png

 

Then create another table, this table would show which customer have product sku and their sales is not 0.

generate table =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            Sheet9,
            "sum_value", CALCULATE (
                SUM ( Sheet9[Sales] ),
                ALLEXCEPT ( Sheet9, Sheet9[CustomerCode], Sheet9[SKU] )
            )
        ),
        [sum_value] <> 0
    ),
    Sheet9[CustomerCode],
    Sheet9[SKU]
)

14.png

 

Finally create a new table, this table would show potential as you expected.

final Table = EXCEPT('crossjoin table','generate table')

15.png

Best Regards
Maggie

 

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

Thanks a lot!!!

d_gosbell
Super User
Super User

So the "trick" to doing this would be to create a disconnected table of products with a distinct list of the SKUs. In the code below I have called this table "Products to Sell" and I have called your original table "Table1" and I deleted the relationship that Power BI automatically created between the 2 SKU columns.

 

Then the following measure will return a 1 or a blank against each customer code if they have the selected product from the "Products To Sell" table. Because Power BI automatically hides rows that have blank values if you put just the customer code/ customer name in a table with this measure it will only list customers that have not bought the selected product.

 

Potential Customers = 
var _selectedSKU = ALLSELECTED('Product To Sell'[SKU])
var _selectedSales = ADDCOLUMNS( DISTINCT(Table1[CustomerCode]), "SkuSales" , CALCULATE(sum(Table1[Sales]), TREATAS(_selectedSKU, Table1[SKU])))
var _filteredSales = FILTER(_selectedSales, [SkuSales] = 0)
return COUNTROWS(_filteredSales)

2019-04-PotentialCustomers.gif

Ritaf
Responsive Resident
Responsive Resident

Hi, and if i do need the connection between the tables, for example if i want my user click on table with

data atached and the report need show him a potential customers from region he chose?

Capture.JPG


@Ritaf wrote:

Hi, and if i do need the connection between the tables, for example if i want my user click on table with

data atached and the report need show him a potential customers from region he chose?

Capture.JPG


If you are talking about doing this using my measure technique then you can possibly do this even if you do have a relationship. The only issue is that the table above that you are using for crossfiltering cannot have the CustomerName or CustomerCode columns that you are showing. If you can work with this restriction the following variation which uses the CROSSFILTER function to dynamically "switch off" the relationship might work for you:

 

Potential Customers = 
var _selectedSKU = ALLSELECTED('Product To Sell'[SKU])
var _selectedSales = CALCULATETABLE(
        ADDCOLUMNS( DISTINCT(Table1[CustomerCode]), "SkuSales" , CALCULATE(sum(Table1[Sales]), TREATAS(_selectedSKU, Table1[SKU])))
        ,CROSSFILTER(Table1[SKU], 'Product To Sell'[SKU],None),ALLEXCEPT(Table1, Table1[CustomerCode])
    )
var _filteredSales = FILTER(_selectedSales, [SkuSales] = 0)
return COUNTROWS(_filteredSales)
Ritaf
Responsive Resident
Responsive Resident

Thank you, i will try it.

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.