Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Klal700
Frequent Visitor

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. 

 

LookupValueWithFallback =
VAR CurrentDate = MAX(CombinationTable[Date])
VAR CurrentRegion = MAX(CombinationTable[Region])

VAR LookupResult =
    CALCULATE(
        MAX('Lookup Table'[Value]),
        FILTER(
            'Lookup Table',
            'Lookup Table'[Date] = CurrentDate &&
            'Lookup Table'[Region] = CurrentRegion
        )
    )
VAR FallbackDate = EOMONTH(CurrentDate, -1)
VAR FallbackResult =
    CALCULATE(
        MAX('Lookup Table'[Value]),
        FILTER(
            'Lookup Table',
            'Lookup Table'[Date]= FallbackDate &&
            'Lookup Table'[Region] = CurrentRegion
        )
    )

RETURN
    IF(
        NOT ISBLANK(LookupResult),
        LookupResult,
        FallbackResult
    )
 
Any idea where I am going wrong? 
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@Klal700 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
    )

 

parry2k_0-1694709351393.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

6 REPLIES 6
parry2k
Super User
Super User

@Klal700 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
    )

 

parry2k_0-1694709351393.png

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you. 

parry2k
Super User
Super User

@Klal700 what is the logic?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@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.  

Klal700
Frequent Visitor

Hi, 

@parry2k 

 

https://www.dropbox.com/scl/fi/ja0sx2wcvfsohnvsi0f9j/Lookup-Value-PBI.pbix?rlkey=gxhqfzpj6mb4vhan4zk...

 

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. 

 

Klal700_0-1694638692608.png

 

 

parry2k
Super User
Super User

@Klal700 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



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.