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
Anonymous
Not applicable

Row by Over Partion in Dax

Hello everyone,
I hope you have a splendid week.
I encountered the following question, and I hope you might help me here.
I tried to "convert" a query in SQL into dax, and I didn't manage to do so.
Here is the SQL query:

select 
ROW_NUMBER() OVER (PARTITION BY employee_id, customer_id ORDER BY Increament_copy_datetime desc) as row_num,
employee_id,
customer_id,
call_status,
Increament_copy_datetime
from tess_reports.fact_calls

The results I'm expecting to get are the one marked in yellow (The one with the highest rank, means the one with the rank of 1).

KatyaK_0-1640641122460.png

 

The idea here is to create a new table with the "yellow-marked" results as a variable (I plan to use this table with other filters and manipulations like so).
I'll appreciate your kind help!
Thanks!

2 ACCEPTED SOLUTIONS
wdx223_Daniel
Super User
Super User

NewTable=TOPN(1,SourceTable,RANKX(ALL(SourceTable[Increament_copy_datetime]),CALCULATE(MAX(SourceTable[Increament_copy_datetime]),ALLEXCEPT(SourceTable,SourceTable[employee_id],SourceTable[customer_id],SourceTable[Increament_copy_datetime])),,ASC))

View solution in original post

smpa01
Super User
Super User

@Anonymous  if you have a table like this

smpa01_0-1640662428981.png

 

The TSQL's ROW_NUMBER() equivalent would be following which you can achieve with a measure from the exisitng table wothout creating any more table

Row_Number = 
RANKX (
    FILTER (
        ALLSELECTED ( fact_calls ),
        fact_calls[customer_id] = MAX ( fact_calls[customer_id] ) --equivalent of PARTITION BY employee_id
            && fact_calls[employee_id] = MAX ( fact_calls[employee_id] )--, customer_id
    ),
    [_Increament_copy_datetime], -- equivalent of ORDER BY Increament_copy_datetime desc
    ,
    DESC
)

 

smpa01_1-1640662632770.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

4 REPLIES 4
smpa01
Super User
Super User

@Anonymous  if you have a table like this

smpa01_0-1640662428981.png

 

The TSQL's ROW_NUMBER() equivalent would be following which you can achieve with a measure from the exisitng table wothout creating any more table

Row_Number = 
RANKX (
    FILTER (
        ALLSELECTED ( fact_calls ),
        fact_calls[customer_id] = MAX ( fact_calls[customer_id] ) --equivalent of PARTITION BY employee_id
            && fact_calls[employee_id] = MAX ( fact_calls[employee_id] )--, customer_id
    ),
    [_Increament_copy_datetime], -- equivalent of ORDER BY Increament_copy_datetime desc
    ,
    DESC
)

 

smpa01_1-1640662632770.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
Anonymous
Not applicable

Thank you too! 

Your method works for me as well!!

appreciate the help:))

wdx223_Daniel
Super User
Super User

NewTable=TOPN(1,SourceTable,RANKX(ALL(SourceTable[Increament_copy_datetime]),CALCULATE(MAX(SourceTable[Increament_copy_datetime]),ALLEXCEPT(SourceTable,SourceTable[employee_id],SourceTable[customer_id],SourceTable[Increament_copy_datetime])),,ASC))

Anonymous
Not applicable

Thank you!!
It worked I appreciate your help :)))

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.