Forum Discussion
Look Up Value with Fallback result
Hi All,
I am trying to create a measure that looks up a value in a lookup table based on a combination of date and region. If that combination doesn't exist in the lookup table, then it should use the value for the previous month for that region.
Here is my Measure, but it is returning blanks for combinations that don't exist in the lookup table.
Anonymous here is the fix and the output:
LookupValueWithFallback = VAR CurrentDate = MAX('Combination Table'[Date]) // Replace with your actual date column VAR CurrentRegion = MAX('Combination Table'[Region]) // Replace with your actual region column VAR LookupResult = CALCULATE( MAX('Lookup Table'[Rolling Headcount]), FILTER( 'Lookup Table', 'Lookup Table'[Date] = CurrentDate && 'Lookup Table'[Region] = CurrentRegion ) ) VAR FallbackDate = EOMONTH(CurrentDate, -2) + 1 VAR FallbackResult = CALCULATE( MAX('Lookup Table'[Rolling Headcount]), FILTER( 'Lookup Table', 'Lookup Table'[Date]= FallbackDate && 'Lookup Table'[Region]= CurrentRegion ) ) RETURN IF( NOT ISBLANK(LookupResult), LookupResult, FallbackResult )
6 Replies
- parry2kSuper User
Anonymous here is the fix and the output:
LookupValueWithFallback = VAR CurrentDate = MAX('Combination Table'[Date]) // Replace with your actual date column VAR CurrentRegion = MAX('Combination Table'[Region]) // Replace with your actual region column VAR LookupResult = CALCULATE( MAX('Lookup Table'[Rolling Headcount]), FILTER( 'Lookup Table', 'Lookup Table'[Date] = CurrentDate && 'Lookup Table'[Region] = CurrentRegion ) ) VAR FallbackDate = EOMONTH(CurrentDate, -2) + 1 VAR FallbackResult = CALCULATE( MAX('Lookup Table'[Rolling Headcount]), FILTER( 'Lookup Table', 'Lookup Table'[Date]= FallbackDate && 'Lookup Table'[Region]= CurrentRegion ) ) RETURN IF( NOT ISBLANK(LookupResult), LookupResult, FallbackResult )- AnonymousNot applicable
Thank you.
- parry2kSuper User
Anonymous it will be easier if you share some data and explain what you are trying to achieve. Read this post to get your answer quickly.
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490 - AnonymousNot applicable
Hi,
Power BI file with some data.
Here, I'd like the value for Sep 2023 for Interiors to be 9 instead of blank and for Strategic Projects to be 24.
- parry2kSuper User
Anonymous what is the logic?
- AnonymousNot applicable
parry2k ,
Look up value based on a combination of date and region. If that value doesn't exist in the lookup table, then use last month's value.