Forum Discussion

SanderVeeken's avatar
SanderVeeken
Icon for Helper III rankHelper III
3 years ago
Solved

DAX using earliest/max date over two tables

Hello everyone,   I have a datamodel of courses with subscribers, each in their own table. They're linked by the unique course ID. The subscriptions have dates, and the courses have starting dates....
  • johnt75's avatar
    3 years ago

    Try

    Average days before course starts =
    AVERAGEX (
        'Courses',
        VAR FirstSubscriptions =
            TOPN (
                'Courses'[Min subscribers],
                RELATEDTABLE ( 'Subscriptions' ),
                'Subscriptions'[Subscription date], ASC
            )
        VAR LatestSubscription =
            MAXX ( FirstSubscriptions, 'Subscription date' )
        RETURN
            'Courses'[Start date] - LatestSubscription
    )