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
charonT
Helper I
Helper I

[Question] Filtering columns in a matrix visual with DAX

I am trying to use a DAX measure to filter the columns in a matrix visualization based on different conditions. The DAX works well if I don't add any fields in the "rows". 

charonT_3-1733329515403.png

However, when I would like to show the breakdown, it will show all the columns.

charonT_2-1733329461201.png

charonT_0-1733330275492.png

This is the DAX I am working on, are there any suggestion to solve this issue? Thank you in advance.

 

 

year filter =
VAR Selection = SELECTEDVALUE('Metrics'[Metrics])
VAR YearSelection = SELECTEDVALUE('Data release'[Year of data release])
VAR Mode = SELECTEDVALUE('STARTMODE'[Mode])

RETURN
IF (
    Selection = "A",
    IF (
        Mode = "Part-time",
        IF (
            MAX(YEAR[YEAR]) <= YearSelection - 4 &&
            MAX(YEAR[YEAR]) >= YearSelection - 7,
            1,
            0
        ),
        IF (
            MAX(YEAR[YEAR]) <= YearSelection - 3 &&
            MAX(YEAR[YEAR]) >= YearSelection - 6,
            1,
            0
        )
    ),
    IF (
        Selection = "B",
        IF (
            Mode = "Part-time",
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 8 &&
                MAX(YEAR[YEAR]) >= YearSelection - 11,
                1,
                0
            ),
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 6 &&
                MAX(YEAR[YEAR]) >= YearSelection - 9,
                1,
                0
            )
        ),
        IF (
            Selection = "C",
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 3 &&
                MAX(YEAR[YEAR]) >= YearSelection - 6,
                1,
                0
            )
        )
    )
)

 

 

 

1 ACCEPTED SOLUTION
charonT
Helper I
Helper I

Thank you! I managed to sort this out on my own. The issue was that one of the DAX commands should have been set to MIN instead of MAX—a silly mistake on my part, haha. Interestingly, I’m not sure why it worked when there were no fields in the rows. The corrected DAX formula is provided below:

 

year filter =
VAR Selection = SELECTEDVALUE('Metrics'[Metrics])
VAR YearSelection = SELECTEDVALUE('Data release'[Year of data release])
VAR Mode = SELECTEDVALUE('STARTMODE'[Mode])

RETURN
IF (
    Selection = "A",
    IF (
        Mode = "Part-time",
        IF (
            MAX(YEAR[YEAR]) <= YearSelection - 4 &&
            MIN(YEAR[YEAR]) >= YearSelection - 7,
            1,
            0
        ),
        IF (
            MAX(YEAR[YEAR]) <= YearSelection - 3 &&
            MIN(YEAR[YEAR]) >= YearSelection - 6,
            1,
            0
        )
    ),
    IF (
        Selection = "B",
        IF (
            Mode = "Part-time",
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 8 &&
                MIN(YEAR[YEAR]) >= YearSelection - 11,
                1,
                0
            ),
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 6 &&
                MIN(YEAR[YEAR]) >= YearSelection - 9,
                1,
                0
            )
        ),
        IF (
            Selection = "C",
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 3 &&
                MIN(YEAR[YEAR]) >= YearSelection - 6,
                1,
                0
            )
        )
    )
)

 

View solution in original post

7 REPLIES 7
charonT
Helper I
Helper I

Thank you! I managed to sort this out on my own. The issue was that one of the DAX commands should have been set to MIN instead of MAX—a silly mistake on my part, haha. Interestingly, I’m not sure why it worked when there were no fields in the rows. The corrected DAX formula is provided below:

 

year filter =
VAR Selection = SELECTEDVALUE('Metrics'[Metrics])
VAR YearSelection = SELECTEDVALUE('Data release'[Year of data release])
VAR Mode = SELECTEDVALUE('STARTMODE'[Mode])

RETURN
IF (
    Selection = "A",
    IF (
        Mode = "Part-time",
        IF (
            MAX(YEAR[YEAR]) <= YearSelection - 4 &&
            MIN(YEAR[YEAR]) >= YearSelection - 7,
            1,
            0
        ),
        IF (
            MAX(YEAR[YEAR]) <= YearSelection - 3 &&
            MIN(YEAR[YEAR]) >= YearSelection - 6,
            1,
            0
        )
    ),
    IF (
        Selection = "B",
        IF (
            Mode = "Part-time",
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 8 &&
                MIN(YEAR[YEAR]) >= YearSelection - 11,
                1,
                0
            ),
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 6 &&
                MIN(YEAR[YEAR]) >= YearSelection - 9,
                1,
                0
            )
        ),
        IF (
            Selection = "C",
            IF (
                MAX(YEAR[YEAR]) <= YearSelection - 3 &&
                MIN(YEAR[YEAR]) >= YearSelection - 6,
                1,
                0
            )
        )
    )
)

 

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

https://drive.google.com/file/d/1SUiO9VjnHY5a3svdI58ElI8tuhcmnz7n/view?usp=sharing

 

Thank you. I have uploaded the sample data. The output I expected is the sex table can filter the year based on the matrix and baseyear selected in the filter, similar to the table on the top.

charonT_0-1733407114235.png

 

I unpivoted the data table to make it usable.

 

Please explain what the year filter is supposed to achieve.

 

lbendlin_0-1733412654723.png

 

Thank you! Here's what I'm aiming to achieve:

If Metric A is selected, the table should display YEAR ranging from BASEYEAR-3 to BASEYEAR-1.

If Metric B is selected, the table should display YEAR ranging from BASEYEAR-4 to BASEYEAR-2.

If Metric C is selected, the table should display YEAR ranging from BASEYEAR-5 to BASEYEAR-3.

 

The year filter works perfectly when I don’t include any rows in the matrix. However, it stops working when I add "SEX" as a row in the table.

 

charonT_0-1733413351626.pngcharonT_1-1733413359593.pngcharonT_2-1733413372744.png

 

Your metric slicer would have to be single select for this to work.

I’m not sure if this is the case. I’ve set the slicer to single select, but the issue persists.

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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