The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
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.
Solved! Go to Solution.
@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
)
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.
@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
)
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.
@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.
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.
@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.
User | Count |
---|---|
70 | |
64 | |
62 | |
49 | |
28 |
User | Count |
---|---|
117 | |
75 | |
61 | |
54 | |
42 |