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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

SUMX tables with many-to-many relationship


Hi, I am trying to implement a Sumx  formula using two tables that have a many to many relationship.

Also I have two more tables that will be used as slicers("Semana" and "Moneda") for the table "TipoCambio1".

 

The formula I was using is:

VAR VENTAS = CALCULATE(SUMX(Hechos_Comercial,Hechos_Comercial[VentaNeta_ML]* RELATED(TipoCambio1[Ratio])),Hechos_Comercial[EsVenta]=1, FILTER(Calendario,Calendario[Semana]=[vMaxSemanaDias] && Calendario[Año] = [vMaxAño]), FILTER(TipoCambio1, TipoCambio1[TCAñoSemana] = [vAñoSemanaUsar]))

 

And the error that is showing is:
The column 'TipoCambio1[Ratio]' either doesn't exist or doesn't have a relationship to any table available in the current context.

I have also tried to use Treatas function without any luck.

Sin título.jpg

How Can I achieve the sumx? 

Please see below the relationship model and how they are connected:

 

 

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

As far as I know , the related function can't be used in many to many relationship. It is used in many to one relationship to get value from one side.

 

In your situation. you need to use relatedtable function:

 

VENTAS =
CALCULATE (
    SUMX (
        Hechos_Comercial,
        Hechos_Comercial[VentaNeta_ML]
            * SUMX ( RELATEDTABLE ( TipoCambio1 ), TipoCambio1[Ratio] )
    ),
    Hechos_Comercial[EsVenta] = 1,
    FILTER (
        Calendario,
        Calendario[Semana] = [vMaxSemanaDias]
            && Calendario[Año] = [vMaxAño]
    ),
    FILTER ( TipoCambio1, TipoCambio1[TCAñoSemana] = [vAñoSemanaUsar] )
)

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

1 REPLY 1
v-deddai1-msft
Community Support
Community Support

Hi @Anonymous ,

 

As far as I know , the related function can't be used in many to many relationship. It is used in many to one relationship to get value from one side.

 

In your situation. you need to use relatedtable function:

 

VENTAS =
CALCULATE (
    SUMX (
        Hechos_Comercial,
        Hechos_Comercial[VentaNeta_ML]
            * SUMX ( RELATEDTABLE ( TipoCambio1 ), TipoCambio1[Ratio] )
    ),
    Hechos_Comercial[EsVenta] = 1,
    FILTER (
        Calendario,
        Calendario[Semana] = [vMaxSemanaDias]
            && Calendario[Año] = [vMaxAño]
    ),
    FILTER ( TipoCambio1, TipoCambio1[TCAñoSemana] = [vAñoSemanaUsar] )
)

 

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

 

Best Regards,

Dedmon Dai

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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