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

Top N basis the filter value

I have a dataset which contains the Name and Joining Date and Salary of some employees. (Hypothetical Scenario, real scenario is different)

 

I have put the Name in the filter.

 

Now I have column chart which shows the name and salary of the employees.

 

By default, the chart shows name and salary of the latest top 10 employees basis the recent joining date.

 

Now the ask here is: when I select any employee name from the filter, the below graph should show the name and salary of top 10 employees who have joined before the selected employee (including the selected one).

 

So to further explain the scenario, consider there are 26 employees whose name are A, B....Z. 
Now suppose they have joined sequentially, like A joined earliest and Z is the latest entry.

 

By default, on the graph, the salary of Z,Y,X... Q employees. 

Now when I select any employee, suppose I selected P from the filter, the graph should show the name and salary of P, O..

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below.

please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_1-1669831188375.png

 

 

Jihwan_Kim_0-1669831155643.png

 

 

Salary expected top10 measure: =
VAR _slicerselect =
    MAX ( 'Employee slicer'[Employee] )
VAR _slicerselectjoindate =
    CALCULATE ( MAX ( Employee[Join date] ), Employee[Employee] = _slicerselect )
VAR _top10table =
    TOPN (
        10,
        FILTER ( ALL ( Employee ), Employee[Join date] <= _slicerselectjoindate ),
        Employee[Join date], DESC
    )
RETURN
    CALCULATE ( SUM ( Employee[Salary] ), KEEPFILTERS ( _top10table ) )

 

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

4 REPLIES 4
Saurabh8437
Frequent Visitor

Thank you very much Jihwan_Kim for your help and support. 

Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below.

please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your datamodel.

 

Jihwan_Kim_1-1669831188375.png

 

 

Jihwan_Kim_0-1669831155643.png

 

 

Salary expected top10 measure: =
VAR _slicerselect =
    MAX ( 'Employee slicer'[Employee] )
VAR _slicerselectjoindate =
    CALCULATE ( MAX ( Employee[Join date] ), Employee[Employee] = _slicerselect )
VAR _top10table =
    TOPN (
        10,
        FILTER ( ALL ( Employee ), Employee[Join date] <= _slicerselectjoindate ),
        Employee[Join date], DESC
    )
RETURN
    CALCULATE ( SUM ( Employee[Salary] ), KEEPFILTERS ( _top10table ) )

 

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.

Hi, one more questions, what if the values are repeated, instead of joining date, you can take them as start of month date and value is repeating no fix number of times, then how can the sum of salary show as per the filter criteria?

Hi,

Could you please provide a sample pbix file's link together with how expected outcome looks like?

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.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.