Forum Discussion

MYDATASTORY's avatar
MYDATASTORY
Icon for Resolver I rankResolver I
6 years ago
Solved

Lookup table based on other table

Hi 

I have a quick question,

I have two separate tables, one table has dates and the other tables have dates and the Finacial year column and I want to do a lookup. I have connected the Purchase dates with the Calendar date, now I need to connect the Sales date with the Calendar Date so I can get the Financial year lookup.

Sales Table with two date columns

Sales IDPurchase DateSales DatesAmountSales Dates (Expected result)
101/04/202002/04/2020 $    10.00FY20-21
201/04/202003/04/2020 $    11.00FY20-21
302/04/202004/04/2020 $    12.00 
403/04/202005/04/2020 $    13.00 
504/04/202006/04/2020 $    14.00 
605/04/202007/04/2020 $    15.00 
706/04/202008/04/2020 $    16.00 
807/04/202009/04/2020 $    17.00 
908/04/202010/04/2020 $    18.00 
1009/04/202011/04/2020 $    19.00 
1110/04/202012/04/2020 $    20.00 
1211/04/202013/04/2020 $    21.00 
1312/04/202014/04/2020 $    22.00 
1413/04/202015/04/2020 $    23.00 
1501/04/197016/04/2020 $    24.00 
1602/04/197010/04/1970 $    25.00 
1703/04/197011/04/1970 $    26.00 
1804/04/197012/04/1970 $    27.00FY70-71
1905/04/197013/04/1970 $    28.00FY70-71
2006/04/197014/04/1970 $    29.00 
2107/04/197015/04/1970 $    30.00 
2208/04/197016/04/1970 $    31.00 
2309/04/197017/04/1970 $    32.00 
2410/04/197018/04/1970 $    33.00 
2511/04/197019/04/1970 $    34.00 
2613/04/202020/04/1970 $    35.00 
2701/04/197021/04/1970 $    36.00 
2802/04/197022/04/1970 $    37.00 
2903/04/197023/04/1970 $    38.00 
3004/04/197024/04/1970 $    39.00 
3105/04/197025/04/1970 $    40.00 
3206/04/197026/04/1970 $    41.00 
3307/04/197027/04/1970 $    42.00 
3408/04/197028/04/1970 $    43.00 
3509/04/197029/04/1970 $    44.00 
3610/04/197030/04/1970 $    45.00 
3711/04/197001/05/1970 $    46.00 

 

FY lookup 

Date FY
01/04/2020FY 20-21
02/04/2020FY 20-21
03/04/2020FY 20-21
04/04/2020FY 20-21
05/04/2020FY 20-21
06/04/2020FY 20-21
07/04/2020FY 20-21
08/04/2020FY 20-21
09/04/2020FY 20-21
10/04/2020FY 20-21
11/04/2020FY 20-21
12/04/2020FY 20-21
13/04/2020FY 20-21
01/04/1970FY 70-71
02/04/1970FY 70-71
03/04/1970FY 70-71
04/04/1970FY 70-71
05/04/1970FY 70-71
06/04/1970FY 70-71
07/04/1970FY 70-71
08/04/1970FY 70-71
09/04/1970FY 70-71
10/04/1970FY 70-71
11/04/1970FY 70-71
  • CNENFRNL's avatar
    CNENFRNL
    6 years ago

    Hi, MYDATASTORY , I tried both TREATAS and USERELATIONSHIP and both seem to work in your case; but the USERELATIONSHIP one is a bit tricky. You may refer to the attached file for more details.

    Nice weekend!

6 Replies

  • MYDATASTORY , Ideally you should have a date table with FY to be part of your date table. Not clear what is the issue.

     

    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
    https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
    https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
    1.Creating Financial Calendar - From Any Month
    https://community.powerbi.com/t5/Community-Blog/Creating-Financial-Calendar-Decoding-Date-and-Calendar-1-5-Power/ba-p/1187441

    examples

    YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
    Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
    This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
    Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
    Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
    Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
  • CNENFRNL's avatar
    CNENFRNL
    Icon for Community Champion rankCommunity Champion

    Hi, MYDATASTORY , as info is limited, what I can do is to make a best guess and a possible solution is to resort to TREATAS func to establish a virtual relationship dedicated to such a lookup. The measure is like this,

    FY Lookup = 
    CALCULATE (
        MAX ( 'Data Table'[FY] ),
        TREATAS ( VALUES ( Sales[Date] ), 'Data Table'[Date] )
    )

     

    Date column comes from Sales table.

    • MYDATASTORY's avatar
      MYDATASTORY
      Icon for Resolver I rankResolver I

      CNENFRNL  Hi, Thanks for that.  I have used this, is working partially,  is not matching some of the dates. I am only getting one FY which is 19-20

      For the below date, I would expect 

      05/06/2020  ==>FY20-21

       

      • CNENFRNL's avatar
        CNENFRNL
        Icon for Community Champion rankCommunity Champion

        MYDATASTORY If you attach a file with a bit more mockup data, especially a complete structure of data model, maybe I or other gurus here could come up with a better solution.