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

Calculate next value of a column with same characteristics

Hi,

 

I'm trying to create a new column (I'll name it "next_date") in which I'd like to have the next date associated to the same product.

 

For example:

-In line 5 there would be 1 - 8/02/2016 - 10/02/2016

-In line 3 and 8 there would be 3 - 8/02/2016 - 8/02/2016 because for each one of the two lines there's another line with the same date.

-If there's no next_date like for line 7 the cell have to remain blank.

 

I started typing a dax formula with CALCULATE function but I can't find a way to properly filter on the same column (date) having a condition of equality based on another column (product ID).

 

 

Cattura.JPG

3 REPLIES 3
v-haibl-msft
Employee
Employee

@AGo

 

You can first add an index column in Query Editor as below.

Calculate next value of a column with same characteristics_1.jpg

 

Then close and apply Query Editor, create a calculate Column with following formula.

Column = 
CALCULATE (
    MAX ( Table1[date] ),
    FILTER (
        ALL ( Table1 ),
        EARLIER ( Table1[product ID] ) = Table1[product ID]
            && EARLIER ( Table1[date] ) <= Table1[date]
            && EARLIER ( Table1[Index] ) <> Table1[Index]
    )
)

Calculate next value of a column with same characteristics_2.jpg

 

Best Regards,

Herbert

Thank you, I think your solution is logically perfect, but the problem is that I tested it on a 400K rows table and it crashes after reaching 13GB RAM, the target is to have it working on a 2 million rows table.

Maybe we can rewrite it as an M (Power Query code) and execute it before the dataset creation?

@AGo

 

How about using following updated DAX formula?

 

Next_Date = 
CALCULATE (
    MIN ( Table1[Date] ),
    FILTER (
        ALLEXCEPT ( Table1, Table1[product ID] ),
        EARLIER ( Table1[date] ) <= Table1[date]
            && EARLIER ( Table1[Index] ) <> Table1[Index]
    )
)

Best Regards,

Herbert

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.