Forum Discussion

JohnnyWind's avatar
JohnnyWind
New Member
5 years ago
Solved

Compare in a bar graph

Dear all ,   I'm quite new in PowerBI, and I guess this question is easy...  I have a table like this one : Incident ID Created date Closed date I1 01/01/2020 02/03/2020 I2 01/01/20...
  • BA_Pete's avatar
    5 years ago

    Hi JohnnyWind ,

     

    You will need a separate calendar table in your data model, this is where you will get the [Month] field from for your chart axis. The easiest way to achieve this is to create a new table in the Data view and paste the following in the formula bar:

    Calendar = 
    ADDCOLUMNS(
        CALENDARAUTO(),
        "Month", FORMAT([Date], "mmm")
    )

     

    Once you have that, you can create relationships as follows:

     

    1) Calendar[Date] (one) to YourTable[Created Date] (many) - ACTIVE relationship

    2) Calendar[Date] (one) to YourTable[Closed Date] (many) - INACTIVE relationship

     

    You would then create the following measures:

     

     

     

    _noofCreated = DISTINCTCOUNT(aTable[Incident ID])
    
    _noofClosed = 
    CALCULATE(
        DISTINCTCOUNT(aTable[Incident ID]),
        USERELATIONSHIP(aTable[Closed date], Calendar[Date])
    )

     

     

    Notice that the _noofClosed measure is different in that it uses CALCULATE and USERELATIONSHIP - this forces Power BI to use your inactive relationship between the calendar table and your table for that measure.

     

    This give me the following output:

     

    Pete

  • v-easonf-msft's avatar
    v-easonf-msft
    5 years ago

    Hi, JohnnyWind

     

    As mentioned by BA_Pete ,you can create a INACTIVE relationship.

    I make a sample file.Hope it can help you ,If it doesn't meet your requirement, please share more details.

    Best Regards,
    Community Support Team _ Eason
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.