Lookup based on Dax Measure

JEB85

Board Regular
Joined
Aug 13, 2010
Messages
238
Hi,

Is it possible in powerpivot to lookup a value based on the direct result of a measure.

In the example below I have various people in column A and have created a dax measure to calculate the age of each person.

What I’d like to be able to do is, based on the person’s age, assign an age category to each as per the below:


PersonAvg. AgeAge Category
Person119.2>10 and <=20
Person262.1>60 and <=70
Person38.0>0 and <= 10
Person429.7>20 and <=30
Person571.1>70 and <=80
Person638.3>30 and <=40
Person79.0>0 and <= 10
Person825.6>20 and <=30
Person947.8>40 and <=50
Person1027.0>20 and <=30

<colgroup><col style="text-align: center;"><col style="text-align: center;"><col style="text-align: center;"></colgroup><tbody>
</tbody>

Can this be done via another dax measure?

Thanks
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You probably want to avoid the worlds ugliest set of IF() statements, and have a table of AgeCategories. Then write a measures, something like:

=CALCULATE(VALUES(AgeCategory[Category]), FILTER(AgeCategory, AgeCategory[MinAge] > People[Age] && AgeCategory[MaxAge] <= People[Age]))

Or ... something like that :)
 
Upvote 0
Thanks for the reply! Will try it when I'm back in work and let you knows how it goes....
 
Upvote 0
Hi,

I now have my fact table with the fields as ‘Person’ and ‘Age’. I have created a measure to calculate Avg. Age of each person which is simply =CALCULATE(max(Ages[Avg Age])) – there is only one record per person so max is fine.

I also now have an age categories table set up as follows:

Min
Max
Age Category
0
50
> 0 and ≤ 50
50
100
> 50 and ≤ 100
100
200
> 100 and ≤ 200
200
300
> 200 and ≤ 300
300
400
> 300 and ≤ 400
400
500
> 400 and ≤ 500
500
600
> 500 and ≤ 600
600
700
> 600 and ≤ 700
700
800
> 700 and ≤ 800
800
900
> 800 and ≤ 900
900
1000
> 900 and ≤ 1000
1000
1E+14
> 1000

<tbody>
</tbody>


I have tried to replicate your formula but must have got it wrong somewhere as it’s delivering blanks. The formula I have to calculate the age category is:

=CALCULATE(VALUES(AgeCategories[Age Category]),filter(AgeCategories,AgeCategories[Min]>Ages[AvgAge]&&AgeCategories[Max]<=Ages[AvgAge]))


Which returns:

Values
Person
AvgAge
AgeCategory
Person1
19.2
Person2
62.1
Person3
8
Person4
29.7
Person5
71.1
Person6
38.3
Person7
9
Person8
25.6
Person9
47.8
Person10
27
Grand Total
71.1

<tbody>
</tbody>

Any idea where I have gone wrong?

Thanks
 
Upvote 0
If I may :)

You need to change the direction of your comparisons:


=CALCULATE(VALUES(AgeCategories[Age Category]),filter(AgeCategories,AgeCategories[Min]<Ages[AvgAge]&&AgeCategories[Max]>=Ages[AvgAge]))
 
Upvote 0

Forum statistics

Threads
1,215,358
Messages
6,124,487
Members
449,165
Latest member
ChipDude83

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