Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Create a static variable based on an expression for a dax measure

Hi,   I'm having difficulty figuring out how to create a static variable within a dax measure. With a normal programming language, i'm use to variables being static at instantiation. However, with...
  • v-deddai1-msft's avatar
    5 years ago

    Hi Anonymous ,

     

    You can use lookupvalue:

    table2 =
    ADDCOLUMNS (
        CROSSJOIN ( VALUES ( 'Table'[Rank] ), VALUES ( 'Table'[Day Of Week] ) ),
        "sales",
            VAR a =
                LOOKUPVALUE (
                    'Table'[Sales],
                    'Table'[Rank], 'Table'[Rank],
                    'Table'[Day Of Week], 'Table'[Day Of Week]
                )
            RETURN
                IF (
                    ISBLANK ( a ),
                    LOOKUPVALUE (
                        'Table'[Sales],
                        'Table'[Rank], 'Table'[Rank] - 1,
                        'Table'[Day Of Week], 'Table'[Day Of Week]
                    ),
                    a
                )
    )

     

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

    Best Regards,

    Dedmon Dai