Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Distribute date ranges into groups automatically

Hello community folks!

 

I am trying to break project date ranges into 3 equal groups (where possible)  I have a list of all dates each project was worked, and want to automatically show which 3rd a date falls into.   See below

 

Project 17/4/20191
Project 17/5/20191
Project 17/6/20192
Project 17/7/20192
Project 17/8/20193
Project 17/9/20193
Project 28/10/20191
Project 28/11/20192
Project 35/4/20191
Project 35/5/20192
Project 35/6/20193

 

I have looked up Rank functions, etc, but am finding nothing where i can set the max number at 3.  Can anyone help me with this?

  • Hi  Anonymous ,

     

    First create a column as below:

    Rank = RANKX(FILTER('Table','Table'[Project #]=EARLIER('Table'[Project #])),'Table'[Dates worked],,ASC)

    Then create a measure as below:

    Thirds = 
    var _max=MAXX(FILTER(ALL('Table'),'Table'[Project #]=MAX('Table'[Project #])),'Table'[Rank])
    var _count=CALCULATE(COUNT('Table'[Project #]),FILTER(ALL('Table'),'Table'[Project #]=MAX('Table'[Project #])))
    Return
    IF(_max<=3,MAX('Table'[Rank]),DIVIDE(MAX('Table'[Rank]),_count/3))
    

    And you will see:

    For the related .pbix file,pls see attached.

     

    Best Regards,
    Kelly
    Did I answer your question? Mark my post as a solution!

11 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Anonymous Sorry, not following this completely. Are you showing us sample source data, expected output, both? If this is sample source data can you post expected output and the logic behind how you want the transformation to happen? 

     

    Are you simply looking for the MAX number per project in the last column? You could do that via Lookup Min/Max - https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/m-p/985814#M434

     

    In your case, 

    Measure =
      VAR __Project = MAX([Project])
      VAR __MaxStatus = MAXX(FILTER('Table',[Project]=__Project),[Status])
    RETURN
      __MaxStatus
    • Anonymous's avatar
      Anonymous
      Not applicable

      Sorry about that Greg_Deckler   I showed the final output i was going for.

       

      I have a list of projects and all the dates those projects were worked on. shown here.

      Project #Dates worked
      Project 17/4/2019
      Project 17/5/2019
      Project 17/6/2019
      Project 17/7/2019
      Project 17/8/2019
      Project 17/9/2019
      Project 28/10/2019
      Project 28/11/2019
      Project 35/4/2019
      Project 35/5/2019
      Project 35/6/2019

       

      What i need to do is break each set of dates, by project, up to a max of 3 groups.(essentially splitting the project duration into 3rds)   The end result would look like this.

      Project #Dates worked 
      Project 17/4/20191
      Project 17/5/20191
      Project 17/6/20192
      Project 17/7/20192
      Project 17/8/20193
      Project 17/9/20193
      Project 28/10/20191
      Project 28/11/20192
      Project 35/4/20191
      Project 35/5/20192
      Project 35/6/20193

       

       

      Does this help?

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

    I wouls use MOD in ths case.

    Lets say you have the output of your rank function in 

    Var _rank = RANK(......)

    Return MOD(_rank,3)+1

     

    This will give you the output only as 1, 2 and 3

    • Anonymous's avatar
      Anonymous
      Not applicable

      Anonymous   I'm sorry, I'm not following. Can you explain in more detail please? 

      • Anonymous's avatar
        Anonymous
        Not applicable

        HI Anonymous 

         

        rank Measure = 

        var _rank = RANKX( 'Table','Table'[Date],,ASC)
        return MOD(_rank,3)+1