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

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.

Reply
ØysteinTv
Frequent Visitor

look up value for a date using YEAR

Hey

 

I have a table with users:

UserPeriodAccountExtra1
user12020-01-01FullA
user12021-01-01FullB
user22020-01-01MobileB
user22021-01-01FullB

EDIT: changed user table to clarify that User is a text and not number field.

 

 

And a table with account costs:

CategorySubCatCostYear
AccountFull2002020
AccountFull2202021
AccountMobile1002020
AccountMobile1102021
Extra1A502020
Extra1A602021
Extra1B1002020
Extra1B1102021


Now I know how to lookup the cost if there is just one value - but how do I match the year as well? 
Can it be done in a measure or do I need to make a column in the User-table? 

And can I make a Matrix that basically is something like this (with a date-slide selected for sometime in 2020 in the example below)

IDAccount Extra Total
 FullMobileAB 
1200 50 250
2 100 100200



2 REPLIES 2
v-zhenbw-msft
Community Support
Community Support

Hi @ØysteinTv ,

 

We can add an ID column in table with account costs to meet you requirement.

 

1. Create a year column in table with users.

 

Year = YEAR('Table'[Period])

 

Look 1.jpg

 

2. Then we can create an ID column.

 

ID = 
var x = CALCULATE(SUM('Table'[User]),FILTER('Table','Table'[Account]='Table (2)'[SubCat] && 'Table'[Year]='Table (2)'[Year] ))
var y = CALCULATE(SUM('Table'[User]),FILTER('Table','Table'[Extra1]='Table (2)'[SubCat] && 'Table'[Year]='Table (2)'[Year]))
return
IF(ISBLANK(x),y,x)

 

Look 2.jpg

 

3. At last we can create a matrix visual, and filter the ID is 1 and 2. The result like this,

 

Look 3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-zhenbw-msft 

 

my bad for just using 1 and 2 as users, the user field is a text field and not a number. 

 

I think my primary concern is how to look up the year in the value table, and using the Category to find the right cost value. 

I'm leaning towards splitting the cost table into seperate tables which are each linked to the main USer-table and running lookups to each seperate table.

 

But still need to understand how to check the year 😄 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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