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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

top selling product per region but with additional filtering of virtual table

Hello All,

I am trying to replicate the logic from this blog -> https://blog.enterprisedna.co/discover-your-top-products-per-region-in-power-bi-wdax/

where the following logic is used:

 

7-7.png

to produce the following:

10-8.png

However I would now like to take things further... how might one adapt this logic to only analyse those products where the quantity sold was more than 100 for example?

My thinking is that I create a virtual table of these products only, along the lines of:

VAR _table = ADDCOLUMNS(VALUES(Products[Product Name]), "Count", CALCULATE(SUM(Sales[Quantity]))

VAR _filteredtable = FILTER(_table, [Count] > 100)


I am stumped however as to how to then use this _filteredtable within the TOPN function as I cannot apply the ALL function to a virtual table.

 

Cannot anyone help solve this problem? Thanks.

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Try

Top 2 Product Per Region =
VAR RankingContext =
    VALUES ( 'Product'[Product Name] )
RETURN
    CALCULATE (
        [Total Sales],
        TOPN (
            2,
            FILTER (
                ALL ( 'Products'[Product Name] ),
                CALCULATE ( SUM ( Sales[Quantity] ) ) > 100
            ),
            [Total Sales]
        ),
        RankingContext
    )

View solution in original post

2 REPLIES 2
johnt75
Super User
Super User

Try

Top 2 Product Per Region =
VAR RankingContext =
    VALUES ( 'Product'[Product Name] )
RETURN
    CALCULATE (
        [Total Sales],
        TOPN (
            2,
            FILTER (
                ALL ( 'Products'[Product Name] ),
                CALCULATE ( SUM ( Sales[Quantity] ) ) > 100
            ),
            [Total Sales]
        ),
        RankingContext
    )
Anonymous
Not applicable

perfect! simpler than expected.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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