Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Query IDs from previous quarter

I'm trying to make a DAX query which can pull all the customer ID from previous quarter and their respective data columns based on slicer selection but I'm not able to figure out the right function t...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Anonymous 

     

    Your Effective Date field must not filter the table from which you bring data into the visual for this to work. It's obvious why this should be so. If your selection filters data in the table, then... your visual will only show the data visible in the current context or a subset of it, not a superset. There are different ways to make it work. I can't see the model, so I'll tell you how I'd most likely do it. I would create a separate table with Effective Dates only that would be either disconnected from the fact table or had an inactive relationship with the fact table. Then I would create a slicer out of Effective Dates and the measure. Let's assume that the table is disconnected. The measure would be:

     

     

    // Best Practice: All columns in a fact table
    // MUST be hidden and slicing is performed only
    // through dimensions. Deviate from this and...
    // you'll be in for nasty suprises sooner or
    // later.
    
    [Show Row] =
    // Efective Dates must be a proper date table
    // marked as a date table in the model. If
    // you want to show only certain dates to the
    // user in a slicer you can have a field in
    // the table that will enable you to filter
    // for the dates in the slicer visual.
    // I assume here that you are placing the Date
    // field in the slicer and this in fact is an
    // effective date. Any other setup and you must
    // adjust the code accordingly.
    var vIsOneEffectiveDateSelected = HASONEVALUE( 'Effective Dates'[Date] )
    // Assuming that ID's are in the fact table, FT.
    var vOneIdIsInScope = ISINSCOPE( FT[ID] )
    var vResult =
        if( vOneIdIsInScope && vIsOneEffectiveDateSelected,
            var vCurrentEffectiveDate = SELECTEDVALUE( FT[EffectiveDate] )
            var vPrevQtrStart =
                MIN( PREVIOUSQUARTER( 'Effective Dates'[Date] ) )
            var vPrevQtrEnd =
                MAX( PREVIOUSQUARTER( 'Effective Dates'[Date] ) )
            var vIDQualifies =
                vPrevQtrStart <= vCurrentEffectiveDate
                &&
                vCurrentEffectiveDate <= vPrevQtrEnd
            RETURN
                vIDQualifies
        )
    return
        1 * vResult