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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
smpa01
Super User
Super User

Ranking Issues 2

@CNENFRNL  @AlexisOlson @jeffrey_wang 

 

I am trying to get a RANK column with WINDOW function. The end result is this with RANKX and without WINDOW function

 

smpa01_0-1674569553077.png

 

I tried using WINDOW function in RANKX like this, but it did not work

 

smpa01_1-1674569712548.png

 

I am not sure where it went wrong

 

By changing this, I can get this. But I am not sure if I should put this code in prod cause I don't understand fully the <row selection> part of WINDOW function and what REL and ABS are internally doing and which would serve my purpose.

smpa01_0-1674570270091.png

 

smpa01_0-1674572942732.png

 

//both the following expression returns desired ranking. I don't understand why
Column = 
RANKX (
    WINDOW (
        1,
        ABS,
        1,
        REL,
        SUMMARIZE ( 'Table', 'Table'[yr], 'Table'[val] ),
        ORDERBY ( 'Table'[val] ),,
        PARTITIONBY ( 'Table'[yr] )
    ),
    'Table'[val],
    ,
    ASC
)

Column = 
RANKX (
    WINDOW (
        1,
        ABS,
        -1,
        ABS,
        SUMMARIZE ( 'Table', 'Table'[yr], 'Table'[val] ),
        ORDERBY ( 'Table'[val] ),,
        PARTITIONBY ( 'Table'[yr] )
    ),
    'Table'[val],
    ,
    ASC
)

 

 

I want to utilize WINDOW here for rank by partition cause I can relate this to TSQL

 

smpa01_0-1674570675288.png

 

 

Thank you in advance

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@jeffrey_wang  I can see see the evaluation context of REL in DAX DEbug output with EVALUATEANDLOG

 

This is simply awesome

 

{
	"expression": "WINDOW (\n                -1,\n                REL,\n                0,\n                REL,\n                SUMMARIZE ( tbl, tbl[yr], tbl[val] ),\n                ORDERBY ( tbl[val] ),\n                KEEP,\n                PARTITIONBY ( tbl[yr] )\n            )",
	"inputs": ["'tbl'[yr]", "'tbl'[val]"],
	"outputs": ["'tbl'[yr]", "'tbl'[val]"],
	"data": [
		{
			"input": [2022, 100],
			"rowCount": 1,
			"output": [
				[2022, 100]
			]
		},
		{
			"input": [2022, 200],
			"rowCount": 2,
			"output": [
				[2022, 100],
				[2022, 200]
			]
		},
		{
			"input": [2022, 300],
			"rowCount": 2,
			"output": [
				[2022, 200],
				[2022, 300]
			]
		},
		{
			"input": [2023, -200],
			"rowCount": 1,
			"output": [
				[2023, -200]
			]
		},
		{
			"input": [2023, -100],
			"rowCount": 2,
			"output": [
				[2023, -200],
				[2023, -100]
			]
		}
	]
}

 

smpa01_0-1674575672532.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

One easy way to see what's going on with a table is to use TOCSV (hover to see line with line breaks).

AlexisOlson_0-1674578278181.png

 

The other version is not the same:

AlexisOlson_1-1674578525846.png

 

From https://dax.guide/window/:

 

  • If FromType is REL, the number of rows to go back (negative value) or forward (positive value) from the current row to get the first row in the window.
  • If FromType is ABS, and From is positive, then it’s the position of the start of the window from beginning of the partition. Indexing is 1-based. For example, 1 means window starts from the beginning of the partition. If From is negative, then it’s the position of the start of the window from the end of the partition. -1 means the last row in the partition.

So, 1, ABS, -1, ABS covers the whole window whereas 1, ABS, 1, REL goes from the start of the window through the the next row (compared to the current row) in the window.

smpa01
Super User
Super User

@jeffrey_wang  I can see see the evaluation context of REL in DAX DEbug output with EVALUATEANDLOG

 

This is simply awesome

 

{
	"expression": "WINDOW (\n                -1,\n                REL,\n                0,\n                REL,\n                SUMMARIZE ( tbl, tbl[yr], tbl[val] ),\n                ORDERBY ( tbl[val] ),\n                KEEP,\n                PARTITIONBY ( tbl[yr] )\n            )",
	"inputs": ["'tbl'[yr]", "'tbl'[val]"],
	"outputs": ["'tbl'[yr]", "'tbl'[val]"],
	"data": [
		{
			"input": [2022, 100],
			"rowCount": 1,
			"output": [
				[2022, 100]
			]
		},
		{
			"input": [2022, 200],
			"rowCount": 2,
			"output": [
				[2022, 100],
				[2022, 200]
			]
		},
		{
			"input": [2022, 300],
			"rowCount": 2,
			"output": [
				[2022, 200],
				[2022, 300]
			]
		},
		{
			"input": [2023, -200],
			"rowCount": 1,
			"output": [
				[2023, -200]
			]
		},
		{
			"input": [2023, -100],
			"rowCount": 2,
			"output": [
				[2023, -200],
				[2023, -100]
			]
		}
	]
}

 

smpa01_0-1674575672532.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.