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
NilR
Post Patron
Post Patron

How to create Ranking Column with Multiple Conditions

I have below table in Power Bi and would like to add calculated column based on two columns, but ranking without tie in order of below combination. for example:

 

ORDER = IF [MAX GOAL) > 0% AND [TAG]='FALSE' THEN [DISTINCT COUNT]
IF [MAX GOAL) > 0% AND [TAG]='TRUE' THEN [DISTINCT COUNT]
IF [[TAG] ='FALSE' THEN [DISTINCT COUNT]
IF [TAG]='TRUE' THEN [DISTINCT COUNT]

 

Here is my table sample with desired result:

 

OrderCompany# Company NameGoal NameMax GOALTAG
11001COMPANY NAME 1GOAL 125%FALSE
21001COMPANY NAME 1GOAL 281%FALSE
31001COMPANY NAME 1GOAL 340%FALSE
41001COMPANY NAME 1GOAL 426%TRUE
51001COMPANY NAME 1GOAL 50%FALSE
61001COMPANY NAME 1GOAL 60%TRUE
11002COMPANY NAME 2GOAL 126%FALSE
21002COMPANY NAME 2GOAL 266%FALSE
31002COMPANY NAME 2GOAL 340%FALSE
41002COMPANY NAME 2GOAL 468%TRUE
51002COMPANY NAME 2GOAL 50%FALSE
61002COMPANY NAME 2GOAL 60%FALSE

 

Here is also the sample code I tried , however I do not know how to encounter other criterias:

 

 

 

 

RANKX (
    FILTER (
        GroupGoalMapping,
        GroupGoalMapping[Company#] = EARLIER ( GroupGoalMapping[Company#] )
    ),
    GroupGoalMapping[Goal_MAX],
    ,
    DESC,
    DENSE
)

 

 

 

 

 

1 ACCEPTED SOLUTION

@NilR, try these calculated columns. The column [Order] is based on the column [Group Order]. The column [Group Order] uses the logic you provided, assigning the appropriate group. The [Group Order] column also concatenates [Goal Name] in order to create a unique column for ranking.

 

Group Order = 
VAR vGoalName = GroupGoalMapping[Goal Name]
VAR vMaxGoal = GroupGoalMapping[Max GOAL]
VAR vTag = GroupGoalMapping[TAG]
VAR vGroup =
    SWITCH (
        TRUE (),
        vMaxGoal > 0
            && vTag = "FALSE", 1,
        vMaxGoal > 0
            && vTag = "TRUE", 2,
        vTag = "FALSE", 3,
        vTag = "TRUE", 4
    )
VAR vResult = vGroup & "-" & vGoalName
RETURN
    vResult

Order = 
VAR vCompany = GroupGoalMapping[Company#]
VAR vCompanyTable =
    FILTER ( GroupGoalMapping, GroupGoalMapping[Company#] = vCompany )
VAR vResult =
    RANKX ( vCompanyTable, GroupGoalMapping[Group Order],, ASC, DENSE )
RETURN
    vResult

 

DataInsights_0-1601562370111.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

hi  @NilR 

Do you mean you want this?

Column = RANKX (
    FILTER (
        GroupGoalMapping,
        GroupGoalMapping[Company#] = EARLIER ( GroupGoalMapping[Company#] )&&GroupGoalMapping[TAG]=EARLIER(GroupGoalMapping[TAG])
    ),
    GroupGoalMapping[Max GOAL],
    ,
    DESC,
    DENSE
)

I could not see your desired result in this table sample.

 

and here is blog about Ranking Column with Multiple Conditions, you could refer to:

https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale

 

Regards,

Lin

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

Thanks for your reply! The order column is actually my desire out come! does it make sense?

@NilR, try these calculated columns. The column [Order] is based on the column [Group Order]. The column [Group Order] uses the logic you provided, assigning the appropriate group. The [Group Order] column also concatenates [Goal Name] in order to create a unique column for ranking.

 

Group Order = 
VAR vGoalName = GroupGoalMapping[Goal Name]
VAR vMaxGoal = GroupGoalMapping[Max GOAL]
VAR vTag = GroupGoalMapping[TAG]
VAR vGroup =
    SWITCH (
        TRUE (),
        vMaxGoal > 0
            && vTag = "FALSE", 1,
        vMaxGoal > 0
            && vTag = "TRUE", 2,
        vTag = "FALSE", 3,
        vTag = "TRUE", 4
    )
VAR vResult = vGroup & "-" & vGoalName
RETURN
    vResult

Order = 
VAR vCompany = GroupGoalMapping[Company#]
VAR vCompanyTable =
    FILTER ( GroupGoalMapping, GroupGoalMapping[Company#] = vCompany )
VAR vResult =
    RANKX ( vCompanyTable, GroupGoalMapping[Group Order],, ASC, DENSE )
RETURN
    vResult

 

DataInsights_0-1601562370111.png

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




worked Great- Thank you!

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.