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

DAX Rownumber() to act like SQL Row_Number() with Dynamic Date

Hello, everyone

 

First off, I'd like to admit that I'm not well versed in DAX.  So, there might be a simpler process.

 

I have a request to simulate the below SQL Server query using a dynamic date in Power BI.  Essentially, the most recent time that a "UniqueID" is used on or before a specific date.

WITH cte_test AS (
SELECT *, ROW_NUMBER() OVER (PARTITION BY UniqueID ORDER BY workDate desc) AS ROWID
FROM table1
WHERE workDate <= '2023-11-01'
)
SELECT max(workDate) AS workDate, status, count(UniqueID) AS countUniqueID, sum(AMOUNT_DUE) AS AMOUNT_DUE, sum(PRINCIPAL_AMOUNT) AS SUM_PRINCIPAL_AMOUNT, sum(INTEREST_AMOUNT) AS sum_INTEREST_AMOUNT
FROM cte_test
WHERE ROWID = 1
GROUP BY status;

I was able to get the data to come in as expected using the following DAX and a multiple select box.  The user wants the ability to change the date with the select box and update the data to use the new date as the "origin".

rwDateRank = ROWNUMBER(
    ALLSELECTED(impData[DWORK_OF_DATE],impData[LOAN_ID])
    ,ORDERBY(
        'impData'[DWORK_OF_DATE],DESC
    )
    , DEFAULT
    , PARTITIONBY('impData'[LOAN_ID])
)

The issue I am running into is that I cannot aggregate the values by Status.  If I remove the Unique ID or Work Date, the data disappears and only shows the headings.

Row Number Test - Detail.png

I need to aggregate the data to show something like the below.

Row Number Test - Summary.png

 

Anyone have any suggestions?

2 REPLIES 2
v-junyant-msft
Community Support
Community Support

Hi @tdewitt274 ,

Please provide some sample date and can you explain how these figures were calculated?

vjunyantmsft_0-1701224598685.png

I need to know the formula to find the DAX for you.

Best Regards,
Dino Tao

Hello, Dino

 

These are just COUNT and SUM the "columns" section of the "Build visual" section.

 

tdewitt274_0-1701353607555.png

 

Thanks,

Todd

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.