Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Bar chart visualization for different years

Hello! 

 

I believe there should be a rather easy solution for this, but for some reason, I haven't been able to do this

I have a list of products with the launching year and the year they will be discontinued. 

I want a bar chart where my horizontal axis is the timeframe and the data being the count of products that will be launched (in one bar) and the products that will be discontinued in another bar. 

 

ProductLaunchedDiscontinued
Socks20212023
Blouse20092021
Pants20202021
Jacket20192040
Hairband20202022
T-shirt20202024
Gloves20082009

 

Does anyone have an idea on how to do this bar chart visualization? 

It will be much appreciated! 

  • You'll need a new table to use for the x-axis.

     

    For example:

    Years =
    SELECTCOLUMNS (
        GENERATESERIES ( MIN ( Products[Launched] ), MAX ( Products[Discontinued] ) ),
        "Year", [Value]
    )

    This is just a list of years between 2008 and 2040.

     

    Put Years[Year] on the x-axis and define your counting measures.

    LaunchedCount =
    CALCULATE (
        COUNTROWS ( Products ),
        Products[Launched] IN VALUES ( Years[Year] )
    )
    
    DiscontinuedCount =
    CALCULATE (
        COUNTROWS ( Products ),
        Products[Discontinued] IN VALUES ( Years[Year] )
    )

     

     

3 Replies

  • You'll need a new table to use for the x-axis.

     

    For example:

    Years =
    SELECTCOLUMNS (
        GENERATESERIES ( MIN ( Products[Launched] ), MAX ( Products[Discontinued] ) ),
        "Year", [Value]
    )

    This is just a list of years between 2008 and 2040.

     

    Put Years[Year] on the x-axis and define your counting measures.

    LaunchedCount =
    CALCULATE (
        COUNTROWS ( Products ),
        Products[Launched] IN VALUES ( Years[Year] )
    )
    
    DiscontinuedCount =
    CALCULATE (
        COUNTROWS ( Products ),
        Products[Discontinued] IN VALUES ( Years[Year] )
    )

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      AlexisOlson Yes, this works perfectly!!! 

       

      I was close yet so far haha 

      Thanks a lot!! 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi AlexisOlson, a quick follow-up question on this. 

      How can I create a measure of "active" products per year? 

      Something like the summing the total number of launched products from previous years that haven't been discontinued, and substracting the discontinued per year. 

      Do I have to create a measure for each year? Or could I have a general one and then add a yearly slicer to my page? 

       

      Any tip will be appreciated!