Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

LookupValue from Table A with a date from Table B within a range o Dates from A.

Hi!

 

I have two tables, Fact Table A that has Prod Code, Price and Date, and the second Table B that has Group Code, Prod Code, Start Date and End Date.

 

So I need to create a calculated column in Fact Table A that retrieves the Group Code from Table B when the Prod Code match and A.Date fall between B.Start Date & B.End Date.

 

Fact Table A

Prod CodePriceDate
100$59/21/2018
101$109/21/2018
101$1110/23/2018
120$2010/23/2018
121$1511/25/2018
100$511/25/2018

 

Table B

Group CodeProd CodeStart DateEnd Date
11008/1/201810/1/2018
210110/1/201811/1/2018
31208/1/201812/1/2018
41218/1/201812/1/2018
510011/1/201812/1/2018

 

Result

Prod CodePriceDateFK_Group_ID
100$59/21/20181
101$109/21/2018null
101$1110/23/20182
120$2010/23/20183
121$1511/25/20184
100$511/25/20185

 

I have aredy readthis thread (similar issue) but had no success with the code.

 

FK_Group_ID = 
CALCULATE (
VALUES ( 'B'[Group Code] ),
FILTER (
'B',
'B'[Start Date] <= 'A'[Date]
&& 'B'[End Date] >= 'A'[Date]
&& 'B'[Prod Code] = 'A'[Prod Code]
)
)

But I´m getting this error A table of multiple values was supplied where a single value was expected.

2 Replies

  • v-cherch-msft's avatar
    v-cherch-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Hi Anonymous

     

    Based on my test, your formula is correct. Please try again and show me the error screenshot. You may also try below formula to test.

    FK_Group_ID2 = 
    CALCULATE (
        MAX( B[Group Code] ),
        FILTER (
            B,
            B[Start Date] <= A[Date]
                && B[End Date] >= A[Date]
                && B[Prod Code] = A[Prod Code]
        )
    )

    Regards,

    Cherie

    • v-cherch-msft's avatar
      v-cherch-msft
      Icon for Microsoft Employee rankMicrosoft Employee

      Hi Anonymous

       

      Have you solved it? Kindly mark my answer as a solution if you feel that makes sense. If not, please share more details for your scenario so that we could help further on it.

       

      Regards,

      Cherie