Forum Discussion

i_stanescu_ro's avatar
2 years ago
Solved

Graph with multiple criteria and comparisons.

Hi guys

 

I need to create one single graph with the following things:

 

evolution on months on

 

sales actual for multiple categories of products

sales target for multiple categories of products

sales actual for the year before for multiple categories of products

 

 

something like:

 

in jan 2023 we sold 30 hats and the target was 40 for this product, and the year before in te same month we sold 50

 

I've created a measure using same period last year to get the numbers for sales actual per each product category

 

 

Any idea how I can create such a graph, I need only one for everything above

 

Pls bare in mind that I am no great expert in PBI

 

 

 

Thanks so much!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi i_stanescu_ro 

     

    Please try this:

    First pf all, I create a set of sample data:

    Then add a new table:

    Table 2 = {"now","Last year"}

    Two measures created:

    actualSales =
    VAR _newtable =
        SELECTEDVALUE ( 'Table 2'[Value] )
    VAR _currentDate =
        MAX ( 'Table'[date] )
    VAR _currentProduct =
        SELECTEDVALUE ( 'Table'[Products] )
    RETURN
        SWITCH (
            _newtable,
            "now",
                CALCULATE (
                    SUM ( 'Table'[actual] ),
                    FILTER (
                        ALLSELECTED ( 'Table' ),
                        YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                ),
            "Last year",
                CALCULATE (
                    SUM ( 'Table'[actual] ),
                    FILTER (
                        ALL ( 'Table' ),
                        YEAR ( 'Table'[date] )
                            = YEAR ( _currentDate ) - 1
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                )
        )
    
    targetSales =
    VAR _newtable =
        SELECTEDVALUE ( 'Table 2'[Value] )
    VAR _currentDate =
        MAX ( 'Table'[date] )
    VAR _currentProduct =
        SELECTEDVALUE ( 'Table'[Products] )
    RETURN
        SWITCH (
            _newtable,
            "now",
                CALCULATE (
                    SUM ( 'Table'[Target] ),
                    FILTER (
                        ALLSELECTED ( 'Table' ),
                        YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                ),
            "Last year",
                CALCULATE (
                    SUM ( 'Table'[Target] ),
                    FILTER (
                        ALL ( 'Table' ),
                        YEAR ( 'Table'[date] )
                            = YEAR ( _currentDate ) - 1
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                )
        )
    

    Then add two slicer with the filed of the products and date separately:

    A line and clustered column chart can be created:

     

    The result is as follow:

     

    If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards

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

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi i_stanescu_ro 

     

    Please try this:

    First pf all, I create a set of sample data:

    Then add a new table:

    Table 2 = {"now","Last year"}

    Two measures created:

    actualSales =
    VAR _newtable =
        SELECTEDVALUE ( 'Table 2'[Value] )
    VAR _currentDate =
        MAX ( 'Table'[date] )
    VAR _currentProduct =
        SELECTEDVALUE ( 'Table'[Products] )
    RETURN
        SWITCH (
            _newtable,
            "now",
                CALCULATE (
                    SUM ( 'Table'[actual] ),
                    FILTER (
                        ALLSELECTED ( 'Table' ),
                        YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                ),
            "Last year",
                CALCULATE (
                    SUM ( 'Table'[actual] ),
                    FILTER (
                        ALL ( 'Table' ),
                        YEAR ( 'Table'[date] )
                            = YEAR ( _currentDate ) - 1
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                )
        )
    
    targetSales =
    VAR _newtable =
        SELECTEDVALUE ( 'Table 2'[Value] )
    VAR _currentDate =
        MAX ( 'Table'[date] )
    VAR _currentProduct =
        SELECTEDVALUE ( 'Table'[Products] )
    RETURN
        SWITCH (
            _newtable,
            "now",
                CALCULATE (
                    SUM ( 'Table'[Target] ),
                    FILTER (
                        ALLSELECTED ( 'Table' ),
                        YEAR ( 'Table'[date] ) = YEAR ( _currentDate )
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                ),
            "Last year",
                CALCULATE (
                    SUM ( 'Table'[Target] ),
                    FILTER (
                        ALL ( 'Table' ),
                        YEAR ( 'Table'[date] )
                            = YEAR ( _currentDate ) - 1
                            && MONTH ( 'Table'[date] ) = MONTH ( _currentDate )
                            && 'Table'[Products] = _currentProduct
                    )
                )
        )
    

    Then add two slicer with the filed of the products and date separately:

    A line and clustered column chart can be created:

     

    The result is as follow:

     

    If the above one can't help you, could you please provide more raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples? It would be helpful to find out the solution. You can refer the following links to share the required info:

    How to provide sample data in the Power BI Forum

    How to Get Your Question Answered Quickly

    And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

    How to upload PBI in Community

    Best Regards

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

    • i_stanescu_ro's avatar
      i_stanescu_ro
      Helper I

      Wow.. this is amazing! Thank you so much for your time on this! You're amazing!!!