DAX Function To Detect Column Label

SimonNU

Board Regular
Joined
Jul 11, 2013
Messages
140
Hi Guys

I'm designing some metrics that change depending on what the column label is. Below is a simple example demonstrating the problem:

Column Labels = January, February, March etc...

I would like put the following into a dax function where ??????? is a function that returns the column label name:


=SWITCH(???????, "January", CALCULATE(...), "February", CALCULATE(...), "March",CALCULATE(...)Thanks!!!</pre>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Assuming you are talking about a measure, and talking about a pivot table (as opposed to like... calculated columns and columns in a power pivot table)... then general pattern you see is...

IF (HASONEVALUE(Calendar[Month]),
IF (VALUES(Calendar[Month]) = "January...", ...

So... I guess your ????? is replaced by VALUES(Calendar[Month]), but you would want to continue to protect against multiple months in a cell (grand totals), else there will be errors and sadness.
 
Upvote 0
I'm receiving the following error:

"Calculation error in measure 'UTILIZATION SHEETS'[99fb0c30-bad9-47aa-ae33-5d0b90626b27]: The value for column 'SOURCE' in table 'COMBINED GL DATA' cannot be determined in the current context. Check that all columns referenced in the calculation expression exist, and that there are no circular dependencies. This can also occur when the formula for a measure refers directly to a column without performing any aggregation--such as sum, average, or count--on that column. The column does not have a single value; it has many values, one for each row of the table, and no row has been specified."

Below is the actual formula. The current year metrics are pulled from 'COMBINED GL DATA' whereas anything else is pulled from 'UTILIZATION SHEETS', hence the need to detect the column label that the measure is calculating under:

=IF(VALUES('COMBINED GL DATA'[SOURCE]="CURRENT YEAR ACTUALS"),

CALCULATE(SUM('UTILIZATION SHEETS'[CS]), FILTER('UTILIZATION SHEETS', 'UTILIZATION SHEETS'[Period]=MAX('UTILIZATION SHEETS'[Period]))),

CALCULATE(SUM('COMBINED GL DATA'[CURRENT PERIOD]),'PROFIT AND LOSS DESCRIPTION MAP'[PL Description]="CS HOURS"))
 
Upvote 0
Oops, ignore the above formula, refer to the below:

=IF(VALUES('COMBINED GL DATA'[SOURCE]="CURRENT YEAR ACTUALS"),

CALCULATE(SUM('COMBINED GL DATA'[CURRENT PERIOD]),'PROFIT AND LOSS DESCRIPTION MAP'[PL Description]="CS HOURS"),

CALCULATE(SUM('UTILIZATION SHEETS'[CS]), FILTER('UTILIZATION SHEETS', 'UTILIZATION SHEETS'[Period]=MAX('UTILIZATION SHEETS'[Period]))))
 
Upvote 0
I've found the below solution. It ain't pretty though:

if(CALCULATE(SUM('COMBINED GL DATA'[CURRENT PERIOD]),'PROFIT AND LOSS DESCRIPTION MAP'[PL Description]="CS HOURS")=0,

CALCULATE(SUM('UTILIZATION SHEETS'[CS]), FILTER('UTILIZATION SHEETS', 'UTILIZATION SHEETS'[Period]=MAX('UTILIZATION SHEETS'[Period]))),

CALCULATE(SUM('COMBINED GL DATA'[CURRENT PERIOD]),'PROFIT AND LOSS DESCRIPTION MAP'[PL Description]="CS HOURS"))
 
Upvote 0
you would want to continue to protect against multiple months in a cell (grand totals), else there will be errors and sadness.
:)

In your case, you want something like ...

Code:
=IF (HASONEVALUE('COMBINED GL DATA'[SOURCE]), 
    IF(VALUES('COMBINED GL DATA'[SOURCE]="CURRENT YEAR ACTUALS"),
       CALCULATE(SUM('UTILIZATION SHEETS'[CS]), FILTER('UTILIZATION SHEETS', 'UTILIZATION SHEETS'[Period]=MAX('UTILIZATION SHEETS'[Period]))),
       CALCULATE(SUM('COMBINED GL DATA'[CURRENT PERIOD]),'PROFIT AND LOSS DESCRIPTION MAP'[PL Description]="CS HOURS"))
    )
 )
 
Upvote 0

Forum statistics

Threads
1,224,034
Messages
6,176,000
Members
452,695
Latest member
Alhassan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top