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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
AlvinLy
Helper II
Helper II

Using Matrix column label in DAX calculation

Hello,

 

I am looking for some help in utilizing a matrix's column label in a DAX calculation. I have a scenario where I want to track previously incurred cost and forecasting future cost. I want the matrix to look something like this

 2024-07-012024-07-152024-07-292024-08-122024-08-262024-09-09
Period HoursPrevious incurredPrevious incurredPrevious incurredForecast CostForecast CostForecast Cost

Cumulative Period

      

 

The row labels is just a simple table

Label
Period Hours
Cumulative Period

 

I have a date table with all the period dates as shown above 

 

I then have two fact tables, one is the incurred costs and another is forecast cost. I wanted to use a DAX formula where if the period date is less than or equal to the data update date, then ise the incurred cost table, and in all other scenarios use the forecast cost table. The problem i'm running to is how to utilize a switch statement while grabbing the column label (period date) as a value for the calculation at each cell. When I use SELECTEDVALUE(Date[Period]) for example, it displays blank. I'm only familiar with tables of  one dimension where SELECTEDVALUE will give me that row's instance of value. 

TLDR, is there a way to extract the column label in a SELECTEDVALUE or similar statement to have conditional matrix value formula, where condition is based on column label. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @AlvinLy 

Based on your description, I created the following sample data:

DateTable:

vjianpengmsft_0-1722308606436.png

ForecastCostsTable:

vjianpengmsft_1-1722308633174.png

IncurredCostsTable:

vjianpengmsft_2-1722308657093.png

LabelTable:

vjianpengmsft_3-1722308685831.png

I created a measure using the following DAX expression:

CostMeasure = 
VAR _current_row = SELECTEDVALUE(LabelTable[Label])
VAR _current_column = SELECTEDVALUE(DateTable[Period])
VAR _update_time = TODAY()
RETURN SWITCH(TRUE(),
    _current_row = "Period Hours",IF(
        _current_column<=_update_time,
        CALCULATE(SUM(IncurredCostsTable[Cost]),'IncurredCostsTable'[Period]=_current_column),
        CALCULATE(SUM(ForecastCostsTable[Cost]),'ForecastCostsTable'[Period]=_current_column)
    )
)

This will dynamically determine whether the current column is smaller than the data update date, and according to what you show, your data update date should be based on the date of your current region. If the update date is less, the cost is calculated using the IncurredCostsTable. Otherwise, use the ForecastCostsTable.

Here are the results:

vjianpengmsft_4-1722308989449.png

I've uploaded the PBIX file I used this time below.

 

 

Best Regards

Jianpeng Li

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

1 REPLY 1
Anonymous
Not applicable

Hi, @AlvinLy 

Based on your description, I created the following sample data:

DateTable:

vjianpengmsft_0-1722308606436.png

ForecastCostsTable:

vjianpengmsft_1-1722308633174.png

IncurredCostsTable:

vjianpengmsft_2-1722308657093.png

LabelTable:

vjianpengmsft_3-1722308685831.png

I created a measure using the following DAX expression:

CostMeasure = 
VAR _current_row = SELECTEDVALUE(LabelTable[Label])
VAR _current_column = SELECTEDVALUE(DateTable[Period])
VAR _update_time = TODAY()
RETURN SWITCH(TRUE(),
    _current_row = "Period Hours",IF(
        _current_column<=_update_time,
        CALCULATE(SUM(IncurredCostsTable[Cost]),'IncurredCostsTable'[Period]=_current_column),
        CALCULATE(SUM(ForecastCostsTable[Cost]),'ForecastCostsTable'[Period]=_current_column)
    )
)

This will dynamically determine whether the current column is smaller than the data update date, and according to what you show, your data update date should be based on the date of your current region. If the update date is less, the cost is calculated using the IncurredCostsTable. Otherwise, use the ForecastCostsTable.

Here are the results:

vjianpengmsft_4-1722308989449.png

I've uploaded the PBIX file I used this time below.

 

 

Best Regards

Jianpeng Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors