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

How to calculate rank of Emp, rank of emp by manger,rank of emp by geo using dax measure

I have Sales table data  with Geo,Manager,Employee and Salesamount column and based on this columns i want to calculate measure which display Rank of all emp ,Rank of Emp by Mgr, Rank of Emp by Geo and display data in table only for top 25 employee by Sales amount. 

I have below measure for this  scenrio but it is working only in metrix not in table

 

EmployeeRank =

var SalesAmount  = calculate( SalesData[SalesAmount],SalesData[Type] = "Won")

var top25SalesAmount =

if ( not ISBLANK([SalesAmount  ]) ,CALCULATE([SalesAmount  ],TOPN(25,all('SalesData'[Employee_Name]),[SalesAmount  ]),values('SalesData'[Employee_Name])))
var emprank = RANKX(ALLSELECTED('SalesData'[Employee_Name]),[top25SalesAmount ],,DESC,Dense)
var mgrrank = RANKX(ALLSELECTED('SalesData'[Mgr_Name_L2]),[top25SalesAmount ],,DESC,Dense)
var georank = RANKX(ALLSELECTED('SalesData'[Geo]),[top25SalesAmount ],,DESC,Dense)
return
SWITCH( TRUE(),
ISINSCOPE('Sales Data'[Employee_Name]),emprank,ISINSCOPE('SalesData'[Mgr_Name_L2]),mgrrank,ISINSCOPE('SalesData'[Geo]),georank)
 
How to Calculate this by using three different measure like Rank of Emp , Rank of Emp by Mgr , Rank of Emp by Geo 
Kishorb_1-1707403021161.png

 


 

4 REPLIES 4
Kishorb
Frequent Visitor

Thanks for update but rather than power query can we handle by using separate measure 

It is better to create calculate columns in Power Query if possible but as you wish:

 

Result:

dufoq3_0-1707753316937.png

 

Don't forget to change table name form Query1 to your table name.

 

Emp

Rank of Emp = RANKX(Query1, [SalesAmount])

 

Emp by Manger

Rank of Emp by Mgr = 
VAR _mng = Query1[Manager]

VAR _result = 
    RANKX(
        FILTER(Query1, [Manager] = _mng),
        [SalesAmount]
    )

RETURN _result

 

Emp by Geo

Rank of Emp by Geo = 
VAR _geo = Query1[Geo]

VAR _result = 
    RANKX(
        FILTER(Query1, [Geo] = _geo),
        [SalesAmount]
    )

RETURN _result

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

dufoq3
Super User
Super User

Hi @Kishorb,

 

Power Query solution:

dufoq3_0-1707751445887.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc9NC4MwDAbg/9Kzh7pPPTo9DTeGU/zCQ2kHlokFrbD9+yU5lPXyJjwJoe17lrCANQ1EMr0+UELO2RD8eb5JsUKNY9/vQr+RI8dtC/EQs9IWB2caXKCta4jntmjkk88F7H/Rj+QptF2H69JYOnPwPR0XvVq6tPcnVzPOyDvHRQFxEwu9MyTOoC1LDKMUMndcVfT8bYISxY7zHD+rpUGGzw4/", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Geo = _t, Manager = _t, Employee = _t, SalesAmount = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"SalesAmount", type number}}),
    SortedRows = Table.Sort(ChangedType,{{"SalesAmount", Order.Descending}}),
    Ad_RankOfEmp = Table.AddIndexColumn(SortedRows, "Rank of Emp", 1, 1, Int64.Type),
    GroupedRows1 = Table.Group(Ad_RankOfEmp, {"Manager"}, {{"RankEmpMgr", each Table.AddIndexColumn(_, "Rank of Emp by Mgr", 1, 1 , Int64.Type), type table}}),
    CombinedTables1 = Table.Combine(GroupedRows1[RankEmpMgr]),
    GroupedrRows2 = Table.Group(CombinedTables1, {"Geo"}, {{"RankEmpGeo", each Table.AddIndexColumn(_, "Rank of Emp by Geo", 1, 1 , Int64.Type), type table}}),
    CombinedTables2 = Table.Combine(GroupedrRows2[RankEmpGeo])
in
    CombinedTables2

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

lbendlin
Super User
Super User

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors
Top Kudoed Authors