Forum Discussion
Using Matrix column label in DAX calculation
- Anonymous2 years ago
Hi, AlvinLy
Based on your description, I created the following sample data:
DateTable:
ForecastCostsTable:
IncurredCostsTable:
LabelTable:
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:
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.
Hi, AlvinLy
Based on your description, I created the following sample data:
DateTable:
ForecastCostsTable:
IncurredCostsTable:
LabelTable:
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:
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.