Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
i_stanescu_ro
Helper I
Helper I

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!

1 ACCEPTED SOLUTION
v-zhengdxu-msft
Community Support
Community Support

Hi @i_stanescu_ro 

 

Please try this:

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

vzhengdxumsft_0-1708655757702.png

Then add a new table:

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

vzhengdxumsft_1-1708655794174.png

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:

vzhengdxumsft_2-1708655943479.pngvzhengdxumsft_3-1708655957183.png

A line and clustered column chart can be created:

vzhengdxumsft_4-1708656022501.png

 

The result is as follow:

vzhengdxumsft_5-1708656053639.pngvzhengdxumsft_6-1708656069220.png

 

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.

View solution in original post

2 REPLIES 2
v-zhengdxu-msft
Community Support
Community Support

Hi @i_stanescu_ro 

 

Please try this:

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

vzhengdxumsft_0-1708655757702.png

Then add a new table:

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

vzhengdxumsft_1-1708655794174.png

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:

vzhengdxumsft_2-1708655943479.pngvzhengdxumsft_3-1708655957183.png

A line and clustered column chart can be created:

vzhengdxumsft_4-1708656022501.png

 

The result is as follow:

vzhengdxumsft_5-1708656053639.pngvzhengdxumsft_6-1708656069220.png

 

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.

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.