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
      • Media
      • 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
    • Getting started
      • Overview
      • Online workshops
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    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: Mann-Kendall Test

    Re: Mann-Kendall Test

    06-21-2022 08:00 AM

    gdonaldson
    New Member
    105 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    Mann-Kendall Test

    ‎08-03-2019 01:32 PM

    @Anonymous reached out to me in a private message and asked me about something called the Mann-Kendall Test. Apparently it is a statistics thing created by evil mathematicians. You can read about it here:

    https://www.real-statistics.com/time-series-analysis/time-series-miscellaneous/mann-kendall-test/

     

    This PBIX file implements the Mann-Kendall Test completely in measures, making it 100% dynamic. The data used in the PBIX file is the same as in the URL from real-statistics. 

     

    The most interesting measure is the one for calculating "S". Calculating "S" looks like it would involve iteration, and it basically does. As we all know, normally iteration is out-of-bounds for DAX but luckily, with some tricky nested DAX we can overcome it!

     

     

    __S = 
    VAR __table1 = ADDCOLUMNS('MK',"__S",
        VAR __value = [Value]
        VAR __table = FILTER(ALLSELECTED('MK'),[ID] < EARLIER([ID]))
        VAR __pos = COUNTX(FILTER(__table,[Value]<__value),[ID])
        VAR __neg = COUNTX(FILTER(__table,[Value]>__value),[ID])
        RETURN
            __pos - __neg)
    RETURN
    SUMX(__table1,[__S])

    Enjoy!

     

    eyJrIjoiODZmN2UzMDktNmUwMy00ODdmLWE1YzMtZDY2MDc0N2ZjOTdhIiwidCI6IjRhMDQyNzQzLTM3M2EtNDNkMi04MjdiLTAwM2Y0YzdiYTFlNSIsImMiOjN9


    @ me in replies or I'll lose your thread!!!
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Learn Power BI 2nd Edition
    Preview file
    2 KB
    Mann-Kendall.pbix
    Labels:
    • Labels:
    • Mathematical
    Message 1 of 16
    5,324 Views
    1
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic
    gdonaldson
    gdonaldson
    New Member
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    Tuesday

    Hello,

    I seem to be having some issues downloading the .pbix file. Wondering if you could try and repost? Not sure if it's an issue on my end. 

    Thanks,

    Graeme

    Message 16 of 16
    105 Views
    0
    Reply
    deschman
    deschman
    Regular Visitor
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎07-02-2021 06:54 AM

    Dear @Greg_Deckler,

     

    I absolutely love your solution and it performs very well. I would like to ask you a question regarding the slope. Mann-Kendall tells us that there is a tren or there is none. for the direction o the trend I read it is advised to use Sen's slope. I tried to figure out if this is the slope that is calculated in your solution. Can you elaborate on this a bit?

     

    Thanks in advance.

    Message 15 of 16
    2,126 Views
    0
    Reply
    Anonymous
    Not applicable
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-06-2019 04:34 AM

    Hi Greg

    I managed to copy use your excellent work to work out the __S for my data and the measure is.

    __s = 
    VAR ComplaintsByFiscalMo = ADDCOLUMNS(VALUES(PMS_COMPLAINT[FISCAL_MON_START_DT]),"CountComplaints", CALCULATE(COUNTROWS(PMS_COMPLAINT)))
    RETURN
    SUMX(ComplaintsByFiscalMo, 
        SUMX(ComplaintsByFiscalMo,
            IF([FISCAL_MON_START_DT]>EARLIER([FISCAL_MON_START_DT])&&[CountComplaints]>EARLIER([CountComplaints]), 1,
            IF([FISCAL_MON_START_DT]>EARLIER([FISCAL_MON_START_DT])&&[CountComplaints]<EARLIER([CountComplaints]), -1))
        )
    )+0

    I cannot for the love of god get the __Freq using my data. 

    i have a sample file here: https://www.dropbox.com/s/bpvte6ms66wv8u5/apples.pbix?dl=0

    Message 3 of 16
    5,158 Views
    0
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-06-2019 12:51 PM

    Hmm @Anonymous, try this for frequency:

     

    __freq = 
    VAR ComplaintsByFiscalMo = ADDCOLUMNS(VALUES(PMS_COMPLAINT[FISCAL_MON_START_DT]),"CountComplaints", CALCULATE(COUNTROWS(PMS_COMPLAINT)))
    VAR __table = GROUPBY(ComplaintsByFiscalMo,[CountComplaints],"__ties",COUNTX(CURRENTGROUP(),[FISCAL_MON_START_DT]))
    VAR __table1 = ADDCOLUMNS(__table,"__ties1",[__ties] - 1)
    VAR __table2 = ADDCOLUMNS(__table1,"__freq",IF([__ties1]=0,0,[__ties1]*([__ties1]+1)*(2*[__ties1]+7)))
    RETURN
    SUMX(__table2,[__freq])

    I should probably break my bad habit of using SUMMARIZE.


    @ me in replies or I'll lose your thread!!!
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Learn Power BI 2nd Edition
    Message 4 of 16
    5,147 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-06-2019 11:31 PM

    Hi Greg, aka DAX Guru.

    the dax is spot on an gives the correct end result.

    The only problem i can see with the whole Mann Kandell calculation for __s and __freq is when you have blank data points. 

    In R you have to input 12 data point for 12 months and months with no data are shown as 0 not blank. So how do you get around this in DAX or how can i amend my formula to add 0 to the table below.

    R Input top part of screen and results bottom part.


    RSceenImage.PNG

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    Power BI Issues to over come

    Capture.PNG

     

     

     

     

     

     

     

     

     

     

     

     

     

     

     

    The Mann kandell falls apart when you have less then 12 data points. if we have 12 data points all the values are 100% spot on with R. 

    Message 5 of 16
    5,123 Views
    0
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-07-2019 08:36 AM

    If you need the freq measure to have a value of 0 instead of BLANK for the values in question, you should be able to do this:

     

    __freq = 
    VAR ComplaintsByFiscalMo = ADDCOLUMNS(VALUES(PMS_COMPLAINT[FISCAL_MON_START_DT]),"CountComplaints", CALCULATE(COUNTROWS(PMS_COMPLAINT)))
    VAR __table = GROUPBY(ComplaintsByFiscalMo,[CountComplaints],"__ties",COUNTX(CURRENTGROUP(),[FISCAL_MON_START_DT]))
    VAR __table1 = ADDCOLUMNS(__table,"__ties1",[__ties] - 1)
    VAR __table2 = ADDCOLUMNS(__table1,"__freq",IF([__ties1]=0,0,[__ties1]*([__ties1]+1)*(2*[__ties1]+7)))
    VAR __sum = SUMX(__table2,[__freq])
    RETURN
    IF(ISBLANK(__sum),0,__sum)
    

    @ me in replies or I'll lose your thread!!!
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Learn Power BI 2nd Edition
    Message 6 of 16
    5,081 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-07-2019 11:11 PM

    Give this man a knigth hood.............................................................

    ok one last quesion, on your original dash board as below  how can you add the mann Kandell Tau calculation. see below. same data.....same values.

     

    mann kandell.PNG

    Message 8 of 16
    5,062 Views
    0
    Reply
    Greg_Deckler
    Super User Greg_Deckler
    Super User
    In response to Anonymous
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-08-2019 06:28 AM

    Assuming that you are referring to Kendall's Tau Quick Measure here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Kendall-s-Tau/m-p/625107.

     

    The short answer is that given the original data that I used for this Mann-Kendall Test, I don't believe I can add Tau to it. The reason is that Kendall's Tau requires two sets of values. In the example above, I used "Interviewer1" and "Interviewer2". These were both columns of values. In the Mann-Kendall Test original data, I only have 1 set of values.

     

    Sooo...I could add another set of values to the data and go that route. Otherwise, if I were to use the single column of values for both concordant and discordant pairs, I would end up with a calculation of 1 for Kendall's Tau. Of course, I wouldn't need to do the calculation in that case, I would just create a measure like Tau = 1. 🙂


    @ me in replies or I'll lose your thread!!!
    Become an expert!: Enterprise DNA
    External Tools: MSHGQM
    YouTube Channel!: Microsoft Hates Greg
    Latest book!:
    Learn Power BI 2nd Edition
    Message 9 of 16
    5,020 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-12-2019 12:23 PM

    Hi Greg

    Is there any reason why my Tau value should be (sllightly out) i have followed your worked example to the letter. Its driving me around the bend. 

    Message 14 of 16
    2,933 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-11-2019 09:05 AM

    Stuck on the following measure

     

    Tau = 
    VAR Mytable = ADDCOLUMNS(VALUES(PMS_COMPLAINT[FISCAL_MON_START_DT]),"CountComplaints", CALCULATE(COUNTROWS(PMS_COMPLAINT)))
    VAR __table1 = ADDCOLUMNS(Mytable,"__Concordant",COUNTROWS(FILTER(Mytable,[FISCAL_MON_START_DT]>EARLIER([FISCAL_MON_START_DT])&&[CountComplaints]>EARLIER([CountComplaints]))))
    VAR __table2 = ADDCOLUMNS(__table1,"__Discordant",COUNTROWS(FILTER(Mytable,[FISCAL_MON_START_DT]>EARLIER([FISCAL_MON_START_DT])&&[CountComplaints]<EARLIER([CountComplaints]))))
    
    VAR __C = SUMX(__table1,[__Concordant])
    VAR __D = SUMX(__table2,[__Discordant])
    
    RETURN
    
    ABS(DIVIDE(__C - __D , __C + __D,0))
    Message 13 of 16
    2,957 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-09-2019 02:22 PM

    Hi Greg

     

    can we use the columns material_ID and FISCAL_MON_START_DT from the PMS complaints table in order to do the Mann Kandell Tau as per your post? 

    Message 12 of 16
    2,992 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-08-2019 06:40 AM

    and yes i was referring to Kandell Tau as per your link.

    Message 11 of 16
    3,006 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-08-2019 06:39 AM

    Hi Greg

    See file sample data where we could use the data and Material_id as two variables. from the main table PMS_Complaints. use material_id and the date column FISCAL_MON_START_DT

     

    https://www.dropbox.com/s/i0nffe5gso2d684/Sample__.pbix?dl=0

    Message 10 of 16
    5,015 Views
    0
    Reply
    Anonymous
    Not applicable
    In response to Greg_Deckler
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-07-2019 09:33 AM
    Let me run this against R. And compair outputs..many thanks.
    Message 7 of 16
    5,078 Views
    0
    Reply
    Anonymous
    Not applicable
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Email to a Friend
    • Report Inappropriate Content

    ‎08-04-2019 05:40 AM

    Hi Greg

     

    Firstly, wow and i am lost for words. The reason i reached out to you, is because you are the guy/person we reach out to when all hope is lost in the word or Power BI.

     

    thank you and god bless.

    A master at work.

     

    Message 2 of 16
    5,219 Views
    2
    Reply

    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

    © 2022 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks