Forum Discussion

Charlesdudu's avatar
Charlesdudu
Regular Visitor
5 years ago
Solved

Adding data depending on 2 links : an ID and a date

Hello,   I'm having difficulties to define a solution to the following problem.   I'm trying to join 2 tables but using different data of the first table depending on a date from the second table...
  • v-henryk-mstf's avatar
    5 years ago

    Hi Charlesdudu ,


    According to your needs, based on the date as the judgment condition, two measures are created to get the correct results. Refer to the following:

    nlocation =
    VAR _sensorid =
        SELECTEDVALUE ( 'Table2'[Sensor ID] )
    VAR _curdate =
        SELECTEDVALUE ( 'Table2'[Date of measure] )
    VAR _insdate =
        CALCULATE (
            MAX ( 'Table1'[Installation date] ),
            FILTER (
                'Table1',
                'Table1'[Sensor ID] = _sensorid
                    && 'Table1'[Uninstallation date] <> BLANK ()
            )
        )
    VAR _uinsdate =
        CALCULATE (
            MAX ( 'Table1'[Uninstallation date] ),
            FILTER (
                'Table1',
                'Table1'[Sensor ID] = _sensorid
                    && 'Table1'[Uninstallation date] <> BLANK ()
            )
        )
    VAR _insdate1 =
        CALCULATE (
            MAX ( 'Table1'[Installation date] ),
            FILTER (
                'Table1',
                'Table1'[Sensor ID] = _sensorid
                    && 'Table1'[Uninstallation date] = BLANK ()
            )
        )
    VAR _location =
        CALCULATE (
            MAX ( 'Table1'[Location] ),
            FILTER (
                'Table1',
                'Table1'[Sensor ID] = _sensorid
                    && 'Table1'[Uninstallation date] <> BLANK ()
            )
        )
    VAR _location1 =
        CALCULATE (
            MAX ( 'Table1'[Location] ),
            FILTER (
                'Table1',
                'Table1'[Sensor ID] = _sensorid
                    && 'Table1'[Uninstallation date] = BLANK ()
            )
        )
    RETURN
        IF ( _curdate >= _insdate && _curdate <= _uinsdate, _location, _location1 )

    Here is the sample pbix file.


    If the problem is still not resolved, please provide detailed error information. Let me know immediately, looking forward to your reply.

     

    Best Regards,
    Henry

     

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