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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Tihannah
Resolver I
Resolver I

Matrix Table Layout (YOY,MOM, Several Measures)

I haven't had any luck, but hoping someone can assist with building a matrix table with the following layout? The business was previously using an excel template in this format. Currently it wants to give me all metrics under a single year.

 

Matrix.PNG

1 ACCEPTED SOLUTION

HI @Tihannah,

You can take a look at the following sample formula and file if helps:

formula = 
VAR currDate =
    MAX ( 'Calendar'[Date] )
VAR prevDate =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1,1 )
VAR currGroup =
    SELECTEDVALUE ( 'Type'[Group] )
RETURN
    IF (
        currDate <= MAXX ( ALLSELECTED ( 'Sample' ), [Date] ),
        SWITCH (
            currGroup,
            "Revenue",
                CALCULATE (
                    SUM ( 'Sample'[Sales] ),
                    FILTER (
                        ALLSELECTED ( 'Sample' ),
                        YEAR ( [Date] ) = YEAR ( currDate )
                            && MONTH ( [Date] ) = MONTH ( currDate )
                    )
                ),
            "Expenses", 2,
            "Profit",
                CALCULATE (
                    SUM ( 'Sample'[Sales] ),
                    FILTER (
                        ALLSELECTED ( 'Sample' ),
                        YEAR ( [Date] ) = YEAR ( currDate )
                            && MONTH ( [Date] ) = MONTH ( currDate )
                    )
                )
                    - CALCULATE (
                        SUM ( 'Sample'[Sales] ),
                        FILTER (
                            ALLSELECTED ( 'Sample' ),
                            YEAR ( [Date] ) = YEAR ( prevDate )
                                && MONTH ( [Date] ) = MONTH ( prevDate )
                        )
                    )
        )
    )

1.PNGRegards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

4 REPLIES 4
v-shex-msft
Community Support
Community Support

HI @Tihannah,

You can create a matrix with calendar table month on rows and year on columns. Then you can create a new table with 'Revenue', 'Expenses','Profit' strings and use it on matrix columns above the year field.

After these steps, your will get a similar structure matrix as the snapshot. You can write a measure formula to extract and check current category field(month, year, custom group) values as condition to lookup raw table records and use switch function to redirect to different expressions based on current category.

My Favorite DAX Feature: SELECTEDVALUE with SWITCH | Winston-Salem Power BI User Group (pbiusergroup...

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Can you create a sample in Power Bi? I don't fully understand.

HI @Tihannah,

You can take a look at the following sample formula and file if helps:

formula = 
VAR currDate =
    MAX ( 'Calendar'[Date] )
VAR prevDate =
    DATE ( YEAR ( currDate ), MONTH ( currDate ) - 1,1 )
VAR currGroup =
    SELECTEDVALUE ( 'Type'[Group] )
RETURN
    IF (
        currDate <= MAXX ( ALLSELECTED ( 'Sample' ), [Date] ),
        SWITCH (
            currGroup,
            "Revenue",
                CALCULATE (
                    SUM ( 'Sample'[Sales] ),
                    FILTER (
                        ALLSELECTED ( 'Sample' ),
                        YEAR ( [Date] ) = YEAR ( currDate )
                            && MONTH ( [Date] ) = MONTH ( currDate )
                    )
                ),
            "Expenses", 2,
            "Profit",
                CALCULATE (
                    SUM ( 'Sample'[Sales] ),
                    FILTER (
                        ALLSELECTED ( 'Sample' ),
                        YEAR ( [Date] ) = YEAR ( currDate )
                            && MONTH ( [Date] ) = MONTH ( currDate )
                    )
                )
                    - CALCULATE (
                        SUM ( 'Sample'[Sales] ),
                        FILTER (
                            ALLSELECTED ( 'Sample' ),
                            YEAR ( [Date] ) = YEAR ( prevDate )
                                && MONTH ( [Date] ) = MONTH ( prevDate )
                        )
                    )
        )
    )

1.PNGRegards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thank you so much!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.