Forum Discussion

arunbyc's avatar
arunbyc
Icon for Helper III rankHelper III
1 year ago
Solved

Probably HASONEVALUE in my code causing unwanted effect? How do I fix this?

My following code displays the description of either (a) work or (b) Materials used in a project depending on whether the record is of type "time" or "materials". The column "lookup_id" in this table...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi arunbyc ,

    I create three tables as you mentioned.


    Then I think you can change the DAX code and you can try the codes below.

    Description = 
    VAR x_id =
        SELECTEDVALUE ( Time_and_Material[lookup_id] )
    VAR display_Value =
        IF (
            HASONEVALUE ( Time_and_Material[lookup_id] )
                && SELECTEDVALUE ( Time_and_Material[type] ) = "time",
            CALCULATE ( SELECTEDVALUE ( work_dim[description] ), work_dim[id] = x_id ),
            CALCULATE (
                SELECTEDVALUE ( material_dim[description] ),
                material_dim[id] = x_id
            )
        )
    RETURN
        IF ( ISINSCOPE ( Time_and_Material[ProjectID] ), display_Value, BLANK () )

     

     

    Best Regards

    Yilong Zhou

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