Forum Discussion
Calculated column that populates approval level based on project type and budget amount
- Anonymous7 years ago
So what I did to solve this was to change the model of the "Approval Levels" table to be Project Area, Min Budget, Max Budget, Approval Level.
Once I had that then I created an "Approval Level" calculated measure in the Projects table with the following code (you may need to adjust to match your model):
Approval Level =IF(HASONEVALUE(Projects[Project Area]) && HASONEVALUE(Projects[ProjectID]),VAR _currentArea = IF(SELECTEDVALUE(Projects[Project Area]) = "IT", "IT", "Non-IT")VAR _currentBudget = SUM(Projects[Budget])VAR _Return = CALCULATE(MAX('Approval Levels'[Approval Level]), 'Approval Levels'[Project Area] = _currentArea, _currentBudget >= 'Approval Levels'[MinBudget], _currentBudget < 'Approval Levels'[MaxBudget])RETURN _Return,BLANK())Since the appropriate approval level will be returned if I'm looking at one project (i.e. you probably don't want to aggregate budgets over all projects and then look-up the approval level but if you have multiple budget lines for one project it'll aggregate those amounts) the HASONEVALUE check verifies that we're looking at one project and one project area, stores those two values in variables, and then the CALCULATE statement filters the Approval Levels table down to that row that matches the Project Area and the budget amount is between the Min and Max Budget fields. Since I know that I'm only looking at one row I can safely use MAX to retrieve the text value.I can't figure out how to include the sample PBIX I created to solve this - if someone knows how to attach a PBIX let me know and I'll upload. I've included a screenshot of the model and the DAX.Hope that helps.Eric - Anonymous6 years ago
Anonymous -
Am I reading the data correctly that one Project ID (in this case 540) can have multiple Project Names? It looks like it has 4 separate names for that one Project ID. Or did you type in the 1, 2, 3, 4 for illustrative purposes?
If it can have multiple names for one ID try changing the code for _currentBudget (I think that's the variable - it's not showing me the original post) from SUM(Project[Budget]) to CALCULATE(SUM(Project[Budget], ALL(Project[Project Name])). I haven't tested that but that essentially "ignores" the project name but still honors the project ID.
I'll see if I can find my original PBIX and try to dummy it up.
Eric
The VAR _currentArea could've been written IF(SELECTEDVALUE(Projects[Project Area] = "IT", SELECTEDVALUE(Projects[Project Area]), "Non-IT") but I got lazy. :) I'm simply checking to see if I'm looking at a non-IT area for when we perform the "lookup" in the Approval Level table.
I'm not sure what your Approval Level table looks like (I'm assuming that it's a separate table). Mine looks like the table on the right in the screenshot. You simply want one column that has the numeric lower boundary of the approval level ladder and one column that has the upper boundary. Have one column that says ">0 and <1000000" won't work for the way I created the solution.
Hope that helps!
Eric
Rookie question: Did you relate your approval level table to the source table?
- Anonymous7 years agoNot applicable
Nope - it's just floating out there all by itself. In fact you probably wouldn't want to so that any filters you applied to the budget table wouldn't flow thru the relationship to the approval level table. And that M:M relationship could cause some headaches.