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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Issue with measure calculation with two tables not directly related

Hello,

 

I am trying to multiply a net price in one table and the exchange rate in another table. Both tables have a relationship to a date table but are not directly related. The exchange rate is the same for each currency for the year. The date value in the Order Table is dd-mm-yyyy and the date value in the Exchange Rate table is yyyy (just thought I would mention it in case it would be relevant).

 

I have tried to apply a measure based on a solution by @marcorusso here: https://www.sqlbi.com/blog/marco/2010/02/09/how-to-relate-tables-in-dax-without-using-relationships/ but without success.

 

My measure

Net USD =
SUMX (
    'SFCC Orders',
    'SFCC Orders'[Net Price]
        CALCULATE (
            VALUES ( 'Exchange Rate'[Exchange Rate] ),
            FILTER (
                'Exchange Rate',
                'Exchange Rate'[country_key] = 'SFCC Orders'[country_key]
                    && 'Exchange Rate'[Year] = 'SFCC Orders'[SFCC Order Date]
            )
        )
)

 

In a visual I can see that the values appear correct in the basic context. i.e Net Price and exchange rate appear correct by country and year.

 

09-06-2020 21-17-17.png

 

However when I create the measure to multiply net price by exchange rate it appears as though the context is incorrect (at least for what I need!) See below.

 

09-06-2020 21-35-32.png

 

Is there a way to get this to work with the relationships to the date table? Any help with clarifying how I could correctly calculate this would be great.

 

Thanks

1 ACCEPTED SOLUTION
marcorusso
Most Valuable Professional
Most Valuable Professional

There was an inversion of two arguments in TREATAS (my fault) and you stored the year as a date instead of as an integer (your fault). Even money 😁

 

Net USD = 
SUMX (
    SUMMARIZE ( 'Test Orders', 'Dates'[Year], 'Test Orders'[country_key] ),
    CALCULATE ( SUM ( 'Test Orders'[Net Price] ) )
        * CALCULATE ( 
            SELECTEDVALUE ( 'Exchange Rate'[Exchange Rate] ),
            TREATAS ( 
                { ( 'Test Orders'[country_key], DATE ( 'Dates'[Year], 1, 1 ) ) },
                'Exchange Rate'[country_key],
                'Exchange Rate'[Year]
            )
        )
)

 

View solution in original post

6 REPLIES 6
marcorusso
Most Valuable Professional
Most Valuable Professional

Assuming you have a Date table (you should have one, otherwise you have many other issues).

 

Net USD =
SUMX (
    SUMMARIZE ( 'SFCC Orders', 'Date'[Year], 'SFCC Orders'[country_key] ),
    CALCULATE ( SUM ( 'SFCC Orders'[Net Price] ) )
        * CALCULATE ( 
            SELECTEDVALUE ( 'Exchange Rate'[Exchange Rate] ),
            TREATAS ( 
                { 'Date'[Year], 'SFCC Orders'[country_key] },
                'Exchange Rate'[country_key],
                'Exchange Rate'[Year]
            )
        )
)
Anonymous
Not applicable

Hello Marco,

 

Many thanks for your reply. I just finished your introductory courses on modeling and DAX and it has helped me immensely, they are really insightful and well produced. Will be signing up for the more advanced courses as soon as I feel confident enough that I have a good grip on the basics.

 

In relation to your response, yes I have a Date table. However, when I create the measure I get a message stating "In the function TREATAS the number of output columns (2) does not match the number of columns in the input table (1).


Do i understand correctly that the input fields are:

{ 'Date'[Year], 'SFCC Orders'[country_key] },

Is the error due to the 'Date'[Year] and 'SFCC Orders'[country_key] residing in different tables?

 

Thank you!

marcorusso
Most Valuable Professional
Most Valuable Professional

Sorry - this is the fixed code:

Net USD =
SUMX (
    SUMMARIZE ( 'SFCC Orders', 'Date'[Year], 'SFCC Orders'[country_key] ),
    CALCULATE ( SUM ( 'SFCC Orders'[Net Price] ) )
        * CALCULATE ( 
            SELECTEDVALUE ( 'Exchange Rate'[Exchange Rate] ),
            TREATAS ( 
                { ( 'Date'[Year], 'SFCC Orders'[country_key] ) },
                'Exchange Rate'[country_key],
                'Exchange Rate'[Year]
            )
        )
)

 

Anonymous
Not applicable

Hi Marco,

The measure is now not causing any error but it only outputs blank rows. I'm not clear on why that might be.

Below is a link to a pbix file with a reduced set of tables and the measure. If you have some time to review it would be greatly appreciated.

 

https://drive.google.com/file/d/1ovwDdxiSj1hCw4Bm0UR96hdpyH4BX8dY/view?usp=sharing

 

Many thanks for your reply and time.

 

 

marcorusso
Most Valuable Professional
Most Valuable Professional

There was an inversion of two arguments in TREATAS (my fault) and you stored the year as a date instead of as an integer (your fault). Even money 😁

 

Net USD = 
SUMX (
    SUMMARIZE ( 'Test Orders', 'Dates'[Year], 'Test Orders'[country_key] ),
    CALCULATE ( SUM ( 'Test Orders'[Net Price] ) )
        * CALCULATE ( 
            SELECTEDVALUE ( 'Exchange Rate'[Exchange Rate] ),
            TREATAS ( 
                { ( 'Test Orders'[country_key], DATE ( 'Dates'[Year], 1, 1 ) ) },
                'Exchange Rate'[country_key],
                'Exchange Rate'[Year]
            )
        )
)

 

Anonymous
Not applicable

I'll take that!  🤣 👍

 

Many thanks.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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