Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

How to Color A Scatter Plot Distribution By Date

Hello All.  I'm new to Power BI.

 

I have built a scatter plot distribution chart.  I have a numerical value on the x-axis and a jitter on the y-axis.  I can't figure out (if it's possible) how to color only the dots of a certain day/month/year/etc.  For example, how would I color all the dots red for April 2021?

 

My timestamp is in the details field (made up of a bunch of discrete dates/times).

 

Any suggestions on how to do this?  Or maybe suggestions on a different way to build the chart?

 

Thanks in advance.

 

  • Hi Anonymous

     

    Please try measure as:

    Measure = 
    IF(
        MONTH(MAX('Table'[Date]))=1,
        "red",
        "blue"
    )

    You can also use 'Year(MAX('Table'[Date]))=2021' or 'MAX('Table'[Date])="2021,08,01"'.

    If you still have some question, please don't hesitate to let me known.‌‌

     

    Best Regards,

    Link

     

    Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

5 Replies

  • v-xulin-mstf's avatar
    v-xulin-mstf
    Community Support

    Hi Anonymous

     

    Please try measure as:

    Measure = 
    IF(
        MONTH(MAX('Table'[Date]))=1,
        "red",
        "blue"
    )

    You can also use 'Year(MAX('Table'[Date]))=2021' or 'MAX('Table'[Date])="2021,08,01"'.

    If you still have some question, please don't hesitate to let me known.‌‌

     

    Best Regards,

    Link

     

    Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-xulin-mstf thanks for this solution.  Is there a way to color every month or quarter and have a legend or is this code only good for coloring a single month/quarter?

      • v-xulin-mstf's avatar
        v-xulin-mstf
        Community Support

        Hi Anonymous

         

        If you need to set different colors for multiple date ranges, you can use switch function.

        Just like: 

        = SWITCH([Month], 1, "red", 2, "green", 3, "yellow", 4, "blue", else)

         

        Best Regards,

        Link

         

        Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

    • Anonymous's avatar
      Anonymous
      Not applicable

      amitchandak thanks for the answer.

       

      Like i said above, I'm very new to Power BI and I'm having a difficult time taking the DAX code for your measure and converting it to what I need it to do.  How would I make a DAX code that will highlight red the dots for April 2021?  I'm struggling with what DAX commands to use for date...would I just use MONTH and YEAR?

       

      Also, once I create a measure, what do I do with it to make it take effect...drag it to one of the details fields?