Forum Discussion

GunnerJ's avatar
GunnerJ
Post Patron
6 years ago
Solved

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...
  • v-juanli-msft's avatar
    6 years ago

    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.

    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 )
    
    

     

    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.