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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
SilviuSaulea
Frequent Visitor

Ranking by Sum in a given limit

Hi,

 

I have a table like this:

 

IdTaskPriorityEffort
1AA22
2BB01
3CC13
4DD43
5EE12
6FF02
7GG32

 

I need to calculate session order column grouping rows over a max value of cumulated value of Effort ordered by priority then by Id.

Let's presume that max effort accepted in session is 4 (this max value will be a prarameter).

The result should be:

 

IdTaskPriorityEffortSession
2BB01Session 1
6FF02Session 1
3CC13Session 2
5EE12Session 3
1AA22Session 3
7GG32Session 4
4DD43Session 5

 

I'm really new to Dax and I have no ideea for this.

Any help will be much apreciated!

 

 

 

5 REPLIES 5
SilviuSaulea
Frequent Visitor

I reiterate the request to be more clear. Let's asume the next data:

IdTaskPriorityEffortDesired result
1AA11Session 001 (Cumulated 4)
2BB21Session 001 (Cumulated 4)
3CC31Session 001 (Cumulated 4)
4DD41Session 001 (Cumulated 4)
5EE51Session 002 (Cumulated 3)
6FF62Session 002 (Cumulated 3)
7GG72Session 003 (Cumulated 4)
8HH82Session 003 (Cumulated 4)
9II92Session 004 (Cumulated 2)
10JJ103Session 005 (Cumulated 3)

So the quest is how to obtain a kind of rank based on SUM of column "Effort" until a specified accepted threshold (value 4 for the given data). The order of summing is by priority and if the sum of previous + current > threshold then current position goes tho the next session and curent sesion cumulated value starts from the current effort.

 

@Anonymous any other ideea?

Anonymous
Not applicable

Hi  @SilviuSaulea ,

 

Here are the steps you can follow:

1. Create calculated column.

Result =
var _sumGroup=
SUMX(
    FILTER(ALL('Table'),'Table'[Priority]=EARLIER('Table'[Priority])),[Effort])
var _sumGroupCum=
SUMX(
    FILTER(ALL('Table'),
    'Table'[Priority]=EARLIER('Table'[Priority])&&
    'Table'[Effort]<=EARLIER('Table'[Effort])),[Effort])
var _rank=
RANKX(
    'Table','Table'[Priority],,ASC,Dense)
var _if=
IF(
    _rank=1&&_sumGroup<=4&&_sumGroupCum<=4,[Rank],
    IF(
       _sumGroup>4&&_sumGroupCum<=4,_rank+1,_rank))
return
"Session"&" "&_if

2. Result:

vyangliumsft_0-1709786777582.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Superb, we are almost there.

I change the priority to show you something:

SilviuSaulea_1-1709807409278.png

I think rank over priority is not enough. From the sample above I don't want to break session if the priority change.

Id 2 should be combined with Id 6 even if they are not on the same priority. Important is how much I cumulate on the curent session order by [Priority,Id] and not to oversize the limit 4.

Look on the next sample to be more accurate:

SilviuSaulea_2-1709808762816.png

 

Anonymous
Not applicable

Hi  @SilviuSaulea ,

 

It's not very clear how Session2 and Session3 are obtained, can you describe the calculation logic of [Session] with a picture or text and we can help you better.

 

Best Regards,

Liu Yang

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

Let's start with Session 1:

we have in order records with id 2 and 6 with efort 1 + 2 = 3 <= limit 4. Prety clear.

Now the next one is id 3 with effort 3 and then id 5 with effort 2. Effort 3 + 2 > 4 then id 3 will have the next session of its own -> Session 2. The condition is that the cumulated consecutive effort to be <= 4. Of course in case of a single effort > 4 then this will have his own session then go forward.

So we have consumed in order Id's 2, 6 and 3 then we just continue the algorithm on the rest.

Id 5 and 1 will group in Session 3, id 7 cannot be gruped with id 4 (effort 2 + 3 > 4) then id 7 will take the next (Session 4) then id 4 will take the last Session 5.

 

Thank you for being interested 🙂

Silviu

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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