Forum Discussion

magnify-bi-com's avatar
4 years ago
Solved

DAX Formula for Cross Table Filtering / Date Logic

I am trying to figure out how to write a DAX solution that requires 2 tables being filtering by Date and Status, respectively.   I have 2 tables that are too big to Merge within the Query Editor, a...
  • AlexisOlson's avatar
    AlexisOlson
    4 years ago

    Yeah. You might want to define it first as a variable though.

     

    Count90 =
    VAR DynamicDate = [DynamicDateMeasure]
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( 'Pass'[Customer] ),
            Sale[Created] > DynamicDate - 90,
            'Pass'[Status] IN { 1, 2 }
        )
  • AlexisOlson's avatar
    AlexisOlson
    4 years ago

    How about this then?

    CountLast90 =
    VAR DynamicDate = TODAY () - 90
    VAR StatusVals = { 1, 2 }
    VAR AddCreatedCol =
        ADDCOLUMNS (
            'Pass',
            "Created", LOOKUPVALUE ( Sale[Created], Sale[ObjID], 'Pass'[SaleID] )
        )
    VAR PassFiltered = FILTER ( AddCreatedCol, [Created] > DynamicDate )
    VAR AddLastCreated =
        ADDCOLUMNS (
            PassFiltered,
            "LastCreated",
                MAXX (
                    FILTER ( PassFiltered, [Customer] = EARLIER ( [Customer] ) ),
                    [Created]
                )
        )
    RETURN
        COUNTROWS (
            SUMMARIZE (
                FILTER ( AddLastCreated, [Created] = [LastCreated] && [Status] IN StatusVals ),
                [Customer]
            )
        )