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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Hermarian
Regular Visitor

Show values by quarter and year

Hi, I have a Matrix visual where I have data for two years, but I want to show quarter data only for the current year and keep prior year as one column only. How do I go about this? 

Thank you

Hermarian_0-1708700941296.png

 

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

Hi @Hermarian 


Please try this:

First of all, I create a set of sample:

vzhengdxumsft_0-1708929351932.png

Then create a new table:

Table 2 = {"_Last year","1Q","2Q","3Q","4Q"}

Then add a measure:

MEASURE =
VAR _newValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _MaxYear =
    YEAR ( MAX ( 'Table'[Date] ) )
VAR _currentQuarter =
    QUARTER ( MAX ( 'Table'[Date] ) )
VAR _Sumvalue =
    SWITCH (
        _newValue,
        "_Last year",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER ( ALLSELECTED ( 'Table' ), YEAR ( 'Table'[Date] ) = _MaxYear - 1 )
            ),
        "1Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 1
                )
            ),
        "2Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 2
                )
            ),
        "3Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 3
                )
            ),
        "4Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 4
                )
            )
    )
RETURN
    _Sumvalue

The result is as follow:

vzhengdxumsft_1-1708929461935.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 @Hermarian 


Please try this:

First of all, I create a set of sample:

vzhengdxumsft_0-1708929351932.png

Then create a new table:

Table 2 = {"_Last year","1Q","2Q","3Q","4Q"}

Then add a measure:

MEASURE =
VAR _newValue =
    SELECTEDVALUE ( 'Table 2'[Value] )
VAR _MaxYear =
    YEAR ( MAX ( 'Table'[Date] ) )
VAR _currentQuarter =
    QUARTER ( MAX ( 'Table'[Date] ) )
VAR _Sumvalue =
    SWITCH (
        _newValue,
        "_Last year",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER ( ALLSELECTED ( 'Table' ), YEAR ( 'Table'[Date] ) = _MaxYear - 1 )
            ),
        "1Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 1
                )
            ),
        "2Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 2
                )
            ),
        "3Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 3
                )
            ),
        "4Q",
            CALCULATE (
                SUM ( 'Table'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table' ),
                    YEAR ( 'Table'[Date] ) = _MaxYear
                        && QUARTER ( 'Table'[Date] ) = 4
                )
            )
    )
RETURN
    _Sumvalue

The result is as follow:

vzhengdxumsft_1-1708929461935.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.

amitchandak
Super User
Super User

@Hermarian , Create a new column in your table and use in visual

 New Qtr =if( [Year] < year(Today()) , [Year], [Qtr])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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