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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Lyssillic
Helper I
Helper I

Next Date in Column Calculate DAX measure

I need to create a measure that calculates the next HoursUnderCapacity based on the next date in the Date column.

 

I was able to accomplish my goal with this example:

need1.PNG
I added one to the filterDate in this code:

need3.PNG

But it only worked because the dates were exactly one day after the other. (ex. 3/8/20, 3/9/20, 3/10/20, ...)


The dates in my actual data are random amounts apart:

need5.PNG

 

How can I accomplish adding the difference between each date into my "lastHUC" dax measure calculation so that it retrieves the correct HoursUnderCapacity based on the next date?

need2.PNG

need4.PNG

I am not able to use EARLIER, because I can only use DirectQuery mode. Unless there's some way to use EARLIER with DirectQuery? I haven't been able to find a way to do that, however.

 

1 ACCEPTED SOLUTION
Lyssillic
Helper I
Helper I

I solved it by adding an index through ROW_NUMBER() called Row, and then using this dax:

MeasureTest = 
    VAR IndexNum = MIN(Final[Row])
    VAR NextIndexNum =
        CALCULATE(
            MIN(Final[Row]),
            FILTER(
                ALLSELECTED (Final),
                Final[Row] > IndexNum
            )
        )

    RETURN CALCULATE (
        SUM(Final[HoursUnderCapacity]),
        FILTER(
            ALL(Final),
            Final[Row] = NextIndexNum
        )
    )

 

View solution in original post

3 REPLIES 3
Lyssillic
Helper I
Helper I

I solved it by adding an index through ROW_NUMBER() called Row, and then using this dax:

MeasureTest = 
    VAR IndexNum = MIN(Final[Row])
    VAR NextIndexNum =
        CALCULATE(
            MIN(Final[Row]),
            FILTER(
                ALLSELECTED (Final),
                Final[Row] > IndexNum
            )
        )

    RETURN CALCULATE (
        SUM(Final[HoursUnderCapacity]),
        FILTER(
            ALL(Final),
            Final[Row] = NextIndexNum
        )
    )

 

VasTg
Memorable Member
Memorable Member

@Lyssillic 

 

Could you post the sample data in a text format (or copy-paste) instead of a screenshot?

 

 

Connect on LinkedIn

@VasTg Yeah!

First example:

DateHoursUnderCapacitylastHUC
3/8/2000
3/9/20011
3/10/201114
3/11/20140
3/12/2000

 

Actual data:

DateHoursUnderCapacitylastHUC (needed)
2/27/200.009.24
3/2/209.243.82
3/4/203.829.25
3/9/209.256.56
3/12/206.568.17
3/17/208.170.00
4/28/200.000.00

 

lastHUC = 
    var filterDate = LASTDATE(Final[Date])
    RETURN CALCULATE(
        SUM(Final[HoursUnderCapacity]),
        ALL(Final),
        Final[Date] = filterDate + 1
    )

 

 

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.