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
rcmv85
Helper I
Helper I

How to create a metric that cross the results of two tables?

Hi!

I have two tables in my Power Query Editor which after some transformations look like this:

Table1:

CompanySymbolUnits
company_name_aAAll numbers in thousands
company_name_bBAll numbers in thousands
company_name_cC 

 

Table2:

Financial KPIYearCompany_NameValue Symbol
KPI_A2022Company_A158057000 A
KPI_A2022Company_Bnull B
KPI_A2022Company_Cnull C
KPI_A2021Company_A136341000 A
KPI_A2021Company_B46213000 B
KPI_A2021Company_C250199000 C
KPI_A2020Company_A127144000 A
KPI_A2020Company_B43475000 B
KPI_A2020Company_C222884000 C
KPI_A2019Company_A155900000 A
KPI_A2019Company_B55537000 B
KPI_A2019Company_C252633000 C
KPI_B2022Company_A-1981000 A
KPI_B2022Company_Bnull B
KPI_B2022Company_Cnull C
KPI_B2021Company_A17937000 A
KPI_B2021Company_B888000 B
KPI_B2021Company_C15382000 C
KPI_B2020Company_A-1279000 A
KPI_B2020Company_B-8008000 B
KPI_B2020Company_C8867000 C
KPI_B2019Company_A47000 A
KPI_B2019Company_B-141000 B
KPI_B2019Company_C13886000 C

 

Now, I have some measures I've created to display some of these KPIs. One of the looks like this:

 

_my_metric = CALCULATE(
    SUM(Table2[Value]), 
    Table2[Financial KPI]="KPI_A"
    )

 

It works OK but I would like to make this metric more accurate in a sense that, depending on the company, the result of this metric may have to be multiplied by 1000 since as you can see on Table1, for some companies, the values are in thousands. So I would like to change this metric with some 'if' conditions that allow me to multiply the KPI values by 1000 when the 'Units' column of Table1 has the string "All numbers in thousands" and leave the value as is, when the 'Units' column is blank. I believe I can link the two tables using the 'Symbol' column as a reference but I'm not sure how to do this. 

Any help?

 

I tried something like the formula below but got no joy. It says that Table2[Symbol] either doesn't Exist or doesn't have a relationship to any table available in the current context.

 

_my_metric = 
VAR units_multiplier = 
    IF(
        SELECTEDVALUE(Table1[Units]) = "All numbers in thousands",
        1000,
        1
    )
RETURN
    CALCULATE(
        SUM(Table2[Value]) * units_multiplier, 
        Table2[Financial KPI]="KPI_A",
        RELATED(Table2[Symbol]) = Table1[Symbol]
    )

 

 

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

try like this:

try like this:

_my_metric = 
VAR _units_multiplier = CALCULATE(MAX('Table1'[Units]),TREATAS(VALUES(Table2[Symbol]), Table1[Symbol]))
VAR _Result=
    IF(
         _units_multiplier= "All numbers in thousands",
        1000,
        1
    )
    RETURN
      CALCULATE(
        SUM(Table2[Value]) * _Result, 
       KEEPFILTERS( Table2[Financial KPI]="KPI_A")
    )
  

View solution in original post

2 REPLIES 2
Ahmedx
Super User
Super User

try like this:

try like this:

_my_metric = 
VAR _units_multiplier = CALCULATE(MAX('Table1'[Units]),TREATAS(VALUES(Table2[Symbol]), Table1[Symbol]))
VAR _Result=
    IF(
         _units_multiplier= "All numbers in thousands",
        1000,
        1
    )
    RETURN
      CALCULATE(
        SUM(Table2[Value]) * _Result, 
       KEEPFILTERS( Table2[Financial KPI]="KPI_A")
    )
  

Thank you @Ahmedx !

It worked perfectly!

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.