Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Identify Consecutive Changed (increased or dropped) Items

Hi,   When use a table or similar visual, is it possible to list the items with metrics those have 3 weeks consecutive changes? either growth or decline. Here is the sample file: sample excel file ...
  • OwenAuger's avatar
    5 years ago

    Hi again Anonymous 

    Attached is a sample PBIX illustrating what I hope is close to what you're wanting 🙂

    When interpreting your requirements, I took it that "3 consecutive weeks of increase" as at week 17 means weeks 15, 16 and 17 form an increasing sequence, i.e. we can ignore the movement from week 14 to 15.

     

    The end result looks like this:

     

     

    There were a few steps I followed to get this working. I won't list all of the DAX here as it is a bit longwinded and you can see it in the PBIX 🙂

    1. Loaded your data from Excel into a table called Metrics.
    2. Created a 'Date' table (in DAX for now) containing various columns including Year, WeekNum and Week Index. Week Index is an index that increments for each week beginning Sunday, so doesn't repeat across years.
    3. Created a 'Reference Date' table that is a copy of 'Date' with column names prefixed with "Reference". This table is used to select the week that will be the reference week at which you will measure growth/decline. I created an inactive relationship between these two tables but that may not be strictly needed.
    4. Created a 'Consecutive Weeks' table which is used as a parameter table to select the number of consecutive weeks.
    5. Created a measure Impressions which is the sum of the Impression columnn.
    6. Created a measure Impression WoW Variance (used in one version of the subsequent measures) that is the week-on-week change in Impressions.
    7. Create measures called Direction Type and Direction Type 2. These both do the same thing. Direction Type performs better but Direction Type 2 is easier to read.
      • If Impressions over the consective weeks form a strictly increasing sequence, then return 1.
      • If Impressions over the consective weeks form a strictly decreasing sequence, then return -1.
      • Otherwise return 0
    8. Created an Impression Segments table. This table defines the segments that you care about, and looks like this:
    9. Create the segmentation measures, based on the pattern from DAX Patterns. I have listed one of the measures below.
    10. I also created a measure Display Date Range to aid filtering the date range on visuals to just the "consecutive weeks range".  This measure has the value 1 when the current date range intersects the "consecutive weeks range". I actually applied it to the visuals as a TopN filter on Week Index. Measure is shown below.
    11. Now the Impression Segmented by... measures can be used in a visual that groups by Segment and URL or Query, producing the result shown above.

     

     

    Display Date Range = 
    VAR ConsWeeks =
        SELECTEDVALUE ( 'Consecutive Weeks'[Consecutive Weeks] )
    VAR DateRangeMax = 
        MAX ( 'Reference Date'[Reference Date] )
    VAR DateRange =
        DATESINPERIOD ( 'Date'[Date], DateRangeMax, -ConsWeeks * 7, DAY )
    VAR InDateRange = 
        CALCULATE (
            NOT ISEMPTY ( 'Date' ),
            KEEPFILTERS ( DateRange )
        )
    RETURN
        InDateRange

     

     

     

    Impressions Segmented by URL = 
    VAR ItemsInSegment =
        FILTER (
            ALLSELECTED ( Metrics[URL] ),
            VAR DirectionOfCurrentItem = [Direction Type]
            VAR SegmentForCurrentItem =
                FILTER (
                    'Impressions Segments',
                    'Impressions Segments'[Direction] = DirectionOfCurrentItem
                )
            VAR InSegment = NOT ISEMPTY ( SegmentForCurrentItem )
            RETURN InSegment
        )
    VAR Result =
        CALCULATE (
            [Impressions],
            KEEPFILTERS ( ItemsInSegment )  -- Applies filter for segmented customers 
        )
    RETURN Result

     

     

    Hopefully that's useful, and you can tweak to suit your exact needs.

     

    All the best!

    Owen