Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have an issue with LOOKUPVALUE returning values incorrectly.
I have two dimension tables in a snowflake scheme. One is 'Personnel' that contains data for 'current age' and 'age on leaving'. The other is an 'Age group' table that buckets those ages into groups, e.g. 30-34, 35-39, etc.
There is an active relationship between the two tables between 'Personnel'[Current Age] and 'Age Groups'[Age], as this is the most commonly-used query (i.e. what age group is a member of staff currently in?).
However, I want to find the age group that a person was in when they left. I am trying to create this as a calculated column in the 'Personnel' table using LOOKUPVALUE, with the following formula:
Age Group On Leaving = LOOKUPVALUE('Age Group'[Age Group],'Age Group'[Age],Personnel[Age On Leaving])
However, this is not responding as expected. I am only getting results for entries where the 'current age' matches the 'age on leaving'. All other entries are returning blank results.
I was advised that LOOKUPVALUE can be used irrespective of relationships between two tables, but it seems as though the active relationship in my model is impacting this calculated column somehow.
How can I get the formula to return values for ALL entries in the 'age on leaving' column?
Solved! Go to Solution.
Hi @Anonymous
Interesting, I can reproduce your issue if the relationship between Personnel and 'Age Group' has Cross Filter Direction set to "Both".
Is that how the relationship is set up in your model?
It would seem the options are:
Age Group On Leaving = VAR AgeOnLeaving = Personnel[Age On Leaving] RETURN CALCULATE ( SELECTEDVALUE ( 'Age Group'[Age Group] ), ALL ( Personnel ), 'Age Group'[Age] = AgeOnLeaving )
Regards,
Owen
Hi @Anonymous
Interesting, I can reproduce your issue if the relationship between Personnel and 'Age Group' has Cross Filter Direction set to "Both".
Is that how the relationship is set up in your model?
It would seem the options are:
Age Group On Leaving = VAR AgeOnLeaving = Personnel[Age On Leaving] RETURN CALCULATE ( SELECTEDVALUE ( 'Age Group'[Age Group] ), ALL ( Personnel ), 'Age Group'[Age] = AgeOnLeaving )
Regards,
Owen
Hi Owen, you're right, the relationship is set to 'Both'. This setup is required due to cross-filtering between different 'branches' of the snowflake schema.
I have therefore tried your alternative solution, and it works like a charm, thank you!
For my own understanding, could you please explain what's happening in that formula to produce the desired result? Thanks very much.
Glad it worked!
I'll just restate the formula with some colour-coding:
Age Group On Leaving = VAR AgeOnLeaving = Personnel[Age On Leaving] RETURN CALCULATE ( SELECTEDVALUE ( 'Age Group'[Age Group] ), ALL ( Personnel ), 'Age Group'[Age] = AgeOnLeaving )
The short description is that the current row's value of Age On Leaving is applied as a filter on 'Age Group'[Age], then the resulting value of Age Group is grabbed.
The steps to do this are (colour-coded):
Regards,
Owen
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
107 | |
94 | |
77 | |
63 | |
50 |
User | Count |
---|---|
147 | |
106 | |
104 | |
87 | |
61 |