skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Office 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Overview
    • Find consulting services
    • Partner showcase
    • Find a partner
    • Become a partner
    • Instructor-led training
      • Overview
      • Guided learning
      • Documentation
      • Webinars
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign In
    • ·
    • Help
    Go To
    • Galleries
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • MBAS Gallery
    • MBAS Gallery 2020
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power BI Community
    • Galleries
    • Quick Measures Gallery
    • Re: Trend spotting

    Re: Trend spotting

    02-25-2021 13:37 PM

    Route217
    Post Prodigy
    1832 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Greg_Deckler
    Super User IV Greg_Deckler
    Super User IV
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    Trend spotting

    ‎02-25-2021 01:34 PM

    This one comes from @Route217 via this thread: Solved: Re: SPC and Shewart Analysis in Power BI - Microsoft Power BI Community

     

    Basically, the desire was to be able to spot trends in a line graph so that the line would be a different color in the event, for example, six consecutive numbers were below the average or above the average. Normally, one might have to resort to SVG or R or Python to do this, but I found a DAX method. Basically, three measures, one for "lower" trends, one for "higher" trends and one for no trend. The lower trend measure is shown below as well as a measure for calculating the lower bound. The rest of the measures are in the PBIX file. There are two versions of the "no trends" measure, one that has breaks in the line and one without breaks in the line.

     

    Lower Trend Measure = 
        VAR __Trend = [Trend]
        VAR __Current = MAX([Index])
        VAR __BaseTable = ALL('Table')
        VAR __Average = AVERAGEX(__BaseTable,[Detections])
        VAR __Detections = MAX([Detections])
        VAR __Table = 
            FILTER(
                ADDCOLUMNS(
                    FILTER(__BaseTable,[Index] >= __Current - __Trend + 1 && [Index] <= __Current + __Trend - 1),
                    "__Diff",[Detections] - __Average
                ),
                [__Diff] < 0
            )
        VAR __Table1 = 
            FILTER(
                ADDCOLUMNS(
                    __Table,
                    "__IndexDiff",[Index] - MAXX(FILTER(__Table,[Index]<EARLIER([Index])),[Index])
                ),
                [__IndexDiff] = 1 || [Index] = [__IndexDiff]
            )
        VAR __Table2 = 
            FILTER(
                ADDCOLUMNS(
                    __Table1,
                    "__IndexDiff2",[Index] - MAXX(FILTER(__Table1,[Index]<EARLIER([Index])),[Index])
                ),
                [__IndexDiff2] = 1 || [Index] = [__IndexDiff2]
            )
    RETURN
        IF(COUNTROWS(__Table2) >= __Trend && __Detections < __Average,__Detections,BLANK())
    
    
    
    
    Lower Bound = 
        VAR __BaseTable = ALL('Table')
        VAR __NoTrend = ADDCOLUMNS(__BaseTable,"__Measure",[No Trend Measure])
        VAR __LowerTrend = ADDCOLUMNS(__BaseTable,"__Measure",[Lower Trend Measure])
        VAR __UpperTrend = ADDCOLUMNS(__BaseTable,"__Measure",[Upper Trend Measure])
    RETURN
        MINX(UNION(UNION(__NoTrend,__LowerTrend),__UpperTrend),[__Measure])

     

     

     

    eyJrIjoiODJmZDhmZGMtNTUyNy00Y2JkLWE0MjQtZmU5YTA2ZGNkYWUwIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    ---------------------------------------

    @ me in replies or I'll lose your thread!!!

    I have a NEW book! 
    DAX Cookbook from Packt
    Over 120 DAX Recipes!




    Did I answer your question? Mark my post as a solution!

    Proud to be a Super User!




    Trendspotting.pbix
    Labels:
    • Labels:
    • Mathematical
    • Other
    Message 1 of 12
    1,836 Views
    1
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    Route217
    Route217 Post Prodigy
    Post Prodigy
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-02-2021 03:34 AM

    Hi Greg

     

    A question on the above trending chart would it be possible to idenitify 6 consective trending points either upwards or downwards in one line...this would be an addition to the above work same file..

    Message 3 of 12
    1,511 Views
    0
    Reply
    Greg_Deckler
    Super User IV Greg_Deckler
    Super User IV
    In response to Route217
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-02-2021 12:39 PM

    @Route217 Well, depends on what you mean by same line. The second page makes it look like a single line. Just a slight variation on the No Trend measure. The main issue with identifying a trend in a single line is that the line color for a line in a Line Chart cannot be conditionally formatted as far as I know. That is the reason I did it in multiple measures so I could get different line colors. Also, no way that I know of to dynamically change the marker either. Now, that being said, there is no reason that if you didn't want to use color as the indicator that you couldn't use a "flag" measure so that when you hovered over a data point it would tell you if it was part of a trend or not. That would definitely be possible. Would essentially mean just having to rewrite the "no trend" measure a bit. Is that what you are looking for or does it need to be a different color in the trends?


    ---------------------------------------

    @ me in replies or I'll lose your thread!!!

    I have a NEW book! 
    DAX Cookbook from Packt
    Over 120 DAX Recipes!




    Did I answer your question? Mark my post as a solution!

    Proud to be a Super User!




    Message 4 of 12
    1,499 Views
    0
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-03-2021 04:51 AM

    Hi Greg - Two Questions

    1. In the Current Trend Analysis my dax is where VAR __Trend = 6 - if i change this to 8 - i am guess the dax well try and find 8 trend point in a row?? see image below

    Capture.PNG

     

     

     

     

     

     

     

     

     

     

    Lower Trend =
    VAR __Trend = 6
    VAR __Current = [Index]
    VAR __Average = [Average Monthly Value]
    VAR __Table =
    FILTER(
    ADDCOLUMNS(
    FILTER(ALL('SPC Chart Data'),[Index] >= __Current - __Trend + 1 && [Index] <= __Current + __Trend - 1),
    "__Diff",[Detections] - [Average Monthly Value]
    ),
    [__Diff] < 0
    )
    VAR __Table1 =
    FILTER(
    ADDCOLUMNS(
    __Table,
    "__IndexDiff",[Index] - MAXX(FILTER(__Table,[Index]<EARLIER([Index])),[Index])
    ),
    [__IndexDiff] = 1 || [Index] = [__IndexDiff]
    )
    VAR __Table2 =
    FILTER(
    ADDCOLUMNS(
    __Table1,
    "__IndexDiff2",[Index] - MAXX(FILTER(__Table1,[Index]<EARLIER([Index])),[Index])
    ),
    [__IndexDiff2] = 1 || [Index] = [__IndexDiff2]
    )
    RETURN
    IF(COUNTROWS(__Table2) >= __Trend && [Detections] < [Average Monthly Value],[Detections],BLANK())
     
     
    2. When i mentinoed yesterday 6 consective point either falling and or raising - this is what i was on about... if this could be added to the current model as additonal Upper and lower bands?
    Capture.PNG
     
    Message 6 of 12
    1,443 Views
    0
    Reply
    Greg_Deckler
    Super User IV Greg_Deckler
    Super User IV
    In response to Route217
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-03-2021 08:55 AM

    @Route217 Ah, right I focused on 6 data points above or below the average. And yes if you changed it to 8, it would look for 8 data points instead of 6. In the PBIX the "Trend" measure is set to 6 so you would want to change that. Let me see about a number of points increasing or decreasing in a row. Shouldn't be too difficult, just a different calculation for "__Diff" I think. I'll take a look and update the PBIX in this post and the post itself.


    ---------------------------------------

    @ me in replies or I'll lose your thread!!!

    I have a NEW book! 
    DAX Cookbook from Packt
    Over 120 DAX Recipes!




    Did I answer your question? Mark my post as a solution!

    Proud to be a Super User!




    Message 7 of 12
    1,435 Views
    0
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-11-2021 12:08 PM

    Hi Greg. Not sure if you had an opportunity to.look at the 6 consecutive data points increasing or decreasing in a row.

    Message 12 of 12
    1,077 Views
    0
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-07-2021 11:54 PM

    Morning, Greg - Hope you had a pleasent weekend. Not sure if managed to look at the 6 consective data points issues on the trending graph?

    Message 11 of 12
    1,217 Views
    0
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-03-2021 02:01 PM

    Hi Greg, if you could kindly add the two measure for 6 consecutive up and down as additionally calculated columns in the table, that would be fantastic. 

     

    Thanks once again

    Message 8 of 12
    1,415 Views
    0
    Reply
    Greg_Deckler
    Super User IV Greg_Deckler
    Super User IV
    In response to Route217
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-12-2021 06:48 AM

    @Route217 - I updated the PBIX to include an Increasing Trend Measure and Decreasing Trend Measure. There is a third page that has these measures. I used a trend of 4 since my data didn't include 6 or 8 increasing or decreasing but you just have to modify the "Trend 2" measure to update from 4 to whatever number you want in your trend. Sorry this took a bit of time, got distracted by other things and I had to swap my thinking on how to identify and flag trends.


    ---------------------------------------

    @ me in replies or I'll lose your thread!!!

    I have a NEW book! 
    DAX Cookbook from Packt
    Over 120 DAX Recipes!




    Did I answer your question? Mark my post as a solution!

    Proud to be a Super User!




    Message 9 of 12
    1,011 Views
    0
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-12-2021 06:49 AM

    Many Thanks greg - much appericated for all your time and efforts. Thanks once again

    Message 10 of 12
    1,010 Views
    2
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎03-02-2021 12:44 PM

    Hi Greg, let me have a think and I'll reply back. Thanks 

    Message 5 of 12
    1,493 Views
    0
    Reply
    Route217
    Route217 Post Prodigy
    Post Prodigy
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎02-25-2021 01:37 PM

    Excellent post Greg...

    Message 2 of 12
    1,832 Views
    2
    Reply
    Preview Exit Preview

    never-displayed

    You must be signed in to add attachments

    never-displayed

    Additional options
    You do not have permission to remove this product association.
     

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    • © 2021 Microsoft
    • Follow Power BI
    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks