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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
GunnerJ
Post Patron
Post Patron

Earlier function errors

In the calculation below the red colored text is giving me an error. Both lines throw "Parameter is not the right type" and "Cannot find name". I have no idea why this is the case and in sample code the creators seem to be using the EARLIER function like myself. Is there something I'm missing?
 
Calc Column =
VAR PreviousRow =
Topn(
1,
FILTER(
Workflow1,
Workflow1[BI_WRKFLW_TASK_SEQ_NBR] < EARLIER( Workflow1[BI_WRKFLW_TASK_SEQ_NBR])
&& Workflow1[BI_SO_NBR] = EARLIER( Workflow1[BI_SO_NBR])
&& Workflow1[BI_WORK_EVENT_CD] = "COMP"
),
Workflow1[BI_WRKFLW_TASK_SEQ_NBR],ASC
)
VAR CurrDateTime =
MAX(Workflow[BI_EVENT_DT_TM])
 
return CurrDateTime - PreviousRow
1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @GunnerJ 

As tested, when i use the "Earlier" function inside "Filter" function to produce a table, it would throw an error, the same as used in Top N function.

Capture6.JPG

You could understand the "Earlier" meaning from this thread.

When using it in Topn or other formula which finally returns a table, it makes no sense in that case.

 

You could try the following workaround to get the expected result.

If you have any question, feel free to let me know.

 

Create measures

 

SUB =
VAR previous =
    CALCULATE (
        MIN ( Sheet7[nbr1] ),
        FILTER (
            ALLSELECTED ( Sheet7 ),
            Sheet7[nbr2] = MAX ( Sheet7[nbr2] )
                && Sheet7[cd] = "COMP"
        )
    )
RETURN
    DATEDIFF ( previous, MAX ( Sheet7[tm] ), HOUR )

Or

SUB 2 =
VAR previous =
    CALCULATE (
        MIN ( Sheet7[nbr1] ),
        FILTER (
            ALLSELECTED ( Sheet7 ),
            Sheet7[nbr2] = MAX ( Sheet7[nbr2] )
                && Sheet7[cd] = "COMP"
        )
    )
VAR current1 =
    CALCULATE ( MAX ( Sheet7[tm] ), ALLSELECTED ( Sheet7 ) )
RETURN
    DATEDIFF ( previous, current1, HOUR )

 

Capture12.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @GunnerJ 

As tested, when i use the "Earlier" function inside "Filter" function to produce a table, it would throw an error, the same as used in Top N function.

Capture6.JPG

You could understand the "Earlier" meaning from this thread.

When using it in Topn or other formula which finally returns a table, it makes no sense in that case.

 

You could try the following workaround to get the expected result.

If you have any question, feel free to let me know.

 

Create measures

 

SUB =
VAR previous =
    CALCULATE (
        MIN ( Sheet7[nbr1] ),
        FILTER (
            ALLSELECTED ( Sheet7 ),
            Sheet7[nbr2] = MAX ( Sheet7[nbr2] )
                && Sheet7[cd] = "COMP"
        )
    )
RETURN
    DATEDIFF ( previous, MAX ( Sheet7[tm] ), HOUR )

Or

SUB 2 =
VAR previous =
    CALCULATE (
        MIN ( Sheet7[nbr1] ),
        FILTER (
            ALLSELECTED ( Sheet7 ),
            Sheet7[nbr2] = MAX ( Sheet7[nbr2] )
                && Sheet7[cd] = "COMP"
        )
    )
VAR current1 =
    CALCULATE ( MAX ( Sheet7[tm] ), ALLSELECTED ( Sheet7 ) )
RETURN
    DATEDIFF ( previous, current1, HOUR )

 

Capture12.JPG

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

parry2k
Super User
Super User

@GunnerJ are you adding this as  measure or column? it will not work in measure



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Yes I was trying as a measure. I thought measures were used for multi row context and columns for single row context? I'm trying to compare one time to another so that's why I went with measure. When I switch to column I get the message "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value." I'm only trying to return one value but it will require a few columns to compute. 

@parry2k 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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