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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

IF statement using row in matrix

Hello,

I am creating a matrix to show a breakdown of orders and the YOY completion percentage of this year compared to last year.

 

The YOY calculation is a measure defined as follows: 

YOY = CALCULATE(SUM(Query2[ORDERS]),Query2[YEAR] = 2021)/CALCULATE(SUM(Query2[ORDERS]),Query2[YEAR] = 2020)
 
But I want this measure to be blank for the previous year and want to use an if statment in my measure to return "" when the year in the row is minimum year present in the data.
 
I've tried to use something like the following:
YOY = IF(Query2[YEAR] = MIN(Query2[YEAR]),"",CALCULATE(SUM(Query2[ORDERS]),Query2[YEAR] = 2021)/CALCULATE(SUM(Query2[ORDERS]),Query2[YEAR] = 2020))
 
But that formula is not accepted by DAX/Power Bi. How can I create a measure that references a value in a row in a matrix (i.e. a column in my data represented as a row header)?

omar_at_trimedx_0-1622580227896.png

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

How about this instead?

 

YOY =
VAR RowYear = MAX( Query2[YEAR] )
RETURN
    DIVIDE (
        SUM ( Query2[ORDERS] ),
        CALCULATE ( SUM ( Query2[ORDERS] ), Query2[ORDERS] = RowYear - 1 )
    )

View solution in original post

1 REPLY 1
AlexisOlson
Super User
Super User

How about this instead?

 

YOY =
VAR RowYear = MAX( Query2[YEAR] )
RETURN
    DIVIDE (
        SUM ( Query2[ORDERS] ),
        CALCULATE ( SUM ( Query2[ORDERS] ), Query2[ORDERS] = RowYear - 1 )
    )

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.