Forum Discussion

acbg's avatar
acbg
Icon for Resolver III rankResolver III
5 years ago
Solved

Dynamic Month Numbering based on different start date for each product

Hi All,

 

We are trying to compare sales on Product across Months in the same chart.

 

Is it possible to do this dynamically in Power BI based on what products are selected in a slicer?

 

For Example, If Product A started on January 2017 then that would be considered Month 1 for Product A.

While Product B start on July 2019 then that would be considered Month 1 for Product B.

 

Chart would look like below:

 

  • Hi, acbg 

     

    I create a sample. You need to create a calculated column.

    Like this:

    MONTHCOLUMN = 
    VAR a =
        RANKX (
            FILTER ( Table1, [product] = EARLIER ( Table1[product] ) ),
            YEAR ( Table1[DATE] ) * 100
                + MONTH ( Table1[DATE] ),
            ,
            ASC,
            DENSE
        )
    RETURN
        "month" & a
    
    

     

    Best Regards

    Janey Guo

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Icon for Community Support rankCommunity Support

    Hi, acbg 

     

    I create a sample. You need to create a calculated column.

    Like this:

    MONTHCOLUMN = 
    VAR a =
        RANKX (
            FILTER ( Table1, [product] = EARLIER ( Table1[product] ) ),
            YEAR ( Table1[DATE] ) * 100
                + MONTH ( Table1[DATE] ),
            ,
            ASC,
            DENSE
        )
    RETURN
        "month" & a
    
    

     

    Best Regards

    Janey Guo

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • acbg yes for this kind of cohort analysis, you need to create a table that will contain, product, date, and calculated month number based on the product start date, and then it is going to be straightforward. A lot of heavy lifting will be done on data modelling and this calculated table.

     

    Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • acbg's avatar
      acbg
      Icon for Resolver III rankResolver III

      parry2k  Thank you! Is there a way to do this more dynamically via Dax? As this was just an example. I have a lot more complex where they want the start dates to be dynamic based on different slicers. Hence the months will change based on different slicers selected.

  • acbg well yes that can be done, it is all going to come down to DAX and disconnected tables but very much possible.

    • acbg's avatar
      acbg
      Icon for Resolver III rankResolver III

      parry2k Thank you for the confirmation. Would you be able to advise how I can achieve this via dax? which dax statement I would use?