Forum Discussion

sudhakar111's avatar
sudhakar111
Helper IV
5 years ago
Solved

Comparing Values between tables

Hello All, I need some help with a requirement. I have 2 tables one is fact table and other is a reference table. The fact table is like the below table.

Rep NamePlaceStateCityDateProductValue   
DaveMarketNew YorkNew York3/1/2021Congelli F0.5   
SteveCenterGeorgiaAtlanta3/1/2021Congelli G1.5   
BillDownTexasAustin3/2/2021Flan2.5   
AlexTownWashingtonSeattle3/3/2021Gelatin2.0   

 

The data needs to be displayed as matrix format. On the matrix, product column values are shown as separate columns, like the attached image.Matrix

The Product values have to be comapred with a refrence table,which has product and value. If the reference table value is less for a product the value has to be shown in red. The reference table just have product and value columns.Linking both the tables based on product. I tried the related function to compare the values but it doesnt seem to be working.

  • Hi, sudhakar111 

     

    You may create a measure as below. The pbix file is attached in the end.

    Visual Control = 
    IF(
        SUM('Fact'[Related])<SUM('Fact'[Value]),
        "red"
    )

     

    Then you can set conditional format as below.

     

    Result:

     

    For further information, please refer to the following document.

    Use conditional formatting in tables 

     

    Best Regards

    Allan

     

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

8 Replies

  • vanessafvg's avatar
    vanessafvg
    Community Champion

    how are you trying to compare it can you show what you have done and demonstrate what are trying to do, what is yoru expected result?

  • v-alq-msft's avatar
    v-alq-msft
    Community Support

    Hi, sudhakar111 

     

    You may create a measure as below. The pbix file is attached in the end.

    Visual Control = 
    IF(
        SUM('Fact'[Related])<SUM('Fact'[Value]),
        "red"
    )

     

    Then you can set conditional format as below.

     

    Result:

     

    For further information, please refer to the following document.

    Use conditional formatting in tables 

     

    Best Regards

    Allan

     

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

    • sudhakar111's avatar
      sudhakar111
      Helper IV

      Thanks a lot v-alq-msft, The solution works perfectly on the same data. Tried to implement it on the original dataset. The related function does not seem to be working. Please find the screenshot attached.

      • v-alq-msft's avatar
        v-alq-msft
        Community Support

        Hi, sudhakar111 

         

        Please check the following considerations about Related function:

        • The RELATED function requires that a relationship exists between the current table and the table with related information. You specify the column that contains the data that you want, and the function follows an existing many-to-one relationship to fetch the value from the specified column in the related table. If a relationship does not exist, you must create a relationship.

        • When the RELATED function performs a lookup, it examines all values in the specified table regardless of any filters that may have been applied.

        • The RELATED function needs a row context; therefore, it can only be used in calculated column expression, where the current row context is unambiguous, or as a nested function in an expression that uses a table scanning function. A table scanning function, such as SUMX, gets the value of the current row value and then scans another table for instances of that value.

        • The RELATED function cannot be used to fetch a column across a limited relationship.

         

        If it is a measure, the row context doesn't exist. So the error occurs.

         

        Best Regards

        Allan

         

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