Forum Discussion

Jeromec's avatar
Jeromec
Frequent Visitor
4 years ago
Solved

How to Plot Active Transactions by Month

I am relatively new to Power BI and I've been searching for ways to solve this particular scenario.    Essentially I have transactions in a fact table that can span X month. For instance a transact...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Jeromec ,

     

    I have built a data sample for test.

    1. Firstly you need a new table with all year-month period between Start Date and End Date

    Year Month =
    DISTINCT (
        SELECTCOLUMNS (
            CALENDAR ( MIN ( 'Table'[Start Date] ), MAX ( 'Table'[End Date] ) ),
            "YearMonth",
                YEAR ( [Date] ) * 100
                    + MONTH ( [Date] ),
            "Year", YEAR ( [Date] ),
            "Month", FORMAT ( [Date], "mmmm" )
        )
    )
    

     

    2. Create a count measure:

    Count of each month =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            'Table',
            YEAR ( [Start Date] ) * 100
                + MONTH ( [Start Date] )
                <= MAX ( 'Dates Table'[YearMonth] )
                && YEAR ( [End Date] ) * 100
                    + MONTH ( [End Date] )
                    >= MAX ( 'Dates Table'[YearMonth] )
        )
    )
    

    3. Create a Stacked column chart, and in order to get the correct sorting, please drag the YearMonth field to the Tooltips pane, below is the final output:

     

    Or if you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file after removing sensitive data.

    Refer to:

    How to Get Your Question Answered Quickly - Microsoft Power BI Community

    How to provide sample data in the Power BI Forum - Microsoft Power BI Community

     

     

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