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
Manuchar
Regular Visitor

YTD amount multiplied with latest rate & multiple currencies

Hello,

 

I can use some help on how to face the following issue:

 

I need to calculate the total sales YTD towards USD when there are sales in multiple currencies.
So what should happen is: total amount local currency * latest rate = YTD USD value.
I have a small test setup with 3 tables: Sales - rates - dates

 

Power BI relationshipData & Output needed

 

Can anyone help me with my issue?

 

Thanks you


Best regards,

Thomas

1 ACCEPTED SOLUTION

@Manuchar

 

Let's try this then

 

Total Sales USD =
CALCULATE (
    SUMX (
        Sales;
        Sales[Amount]
            * CALCULATE (
                VALUES ( Rate[Rate] );
                TOPN (
                    1;
                    CALCULATETABLE ( Rate; FILTER ( Rate; Rate[Currency] = Sales[Currency] ) );
                    Rate[Closing Date]; DESC
                )
            )
    );
    DATESYTD ( 'Date'[Date] )
)

View solution in original post

8 REPLIES 8
v-shex-msft
Community Support
Community Support

Hi @Manuchar,

You can try to use following measure to get total YTD sales based on selected date.

Selected YTD = 
VAR _currency =
    VALUES ( 'Currency'[Currency] )
VAR _selected =
    MAXX ( ALLSELECTED ( DateTable[Date] ), [Date] )
VAR temp =
    GROUPBY (
        SUMMARIZE (
            ALL( 'Sales Records' ),
            [Currency],
            [Amount],
            "Rate",
            VAR _lastdate =
                CALCULATE (
                    MAX ( 'Currency'[Closing Date] ),
                    FILTER (
                        ALL ( 'Currency' ),
                        Currency[Currency] <= EARLIER ( 'Sales Records'[Currency] )
                            && [Closing Date] = _selected
                    )
                )
            RETURN
                LOOKUPVALUE (
                    'Currency'[Rate],
                    'Currency'[Currency], 'Sales Records'[Currency],
                    'Currency'[Closing Date], _lastdate
                )
        ),
        [Currency],
        "Total", SUMX ( CURRENTGROUP (), [Rate] * [Amount] )
    )
RETURN
    SUMX ( FILTER ( temp, [Currency] IN _currency ), [Total] )

60.gif

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
AlB
Super User
Super User

Hi  @Manuchar

 

How about 

1. Place  'Date'[Date] in the rows of a matrix visual

2. Place this measure in values of your matrix:

 

 

Measure =
CALCULATE (
    SUMX (
        Sales,
        Sales[Amount]
            * LOOKUPVALUE (
                Rate[Rate],
                Rate[Date], Sales[Date],
                Rate[Currency], Sales[Currency]
            )
    ),
    DATESYTD ( 'Date'[Date] )
)

 

 

hi @AlB

the measures works but it's not the one I need.
The measure calculates each month against the rate of the month and not the latest rate only.
In this example the difference is not so large so it isn't really noticeble but with greater numbers this will increase inmediatly.

 

This is the difference between your formula and the one I need:

 

Difference

 

best regards,

Thomas

@Manuchar

I see. Try this then. If it doesn't work please post the sample data in text format so that it can be readily copied. Then I can run a quick test before answering again.

 

Measure =
CALCULATE (
    SUMX (
        Sales,
        Sales[Amount]
            * LASTNONBLANK (
                CALCULATETABLE ( VALUES ( Rate[Rate] ), Rate[Currency] = Sales[Currency] ),
                1
            )
    ),
    DATESYTD ( 'Date'[Date] )
)

 

@AlB

I got the following error when trying that measure.

 

2019-01-03 16_57_15-Untitled - Power BI Desktop (August 2018).png

 

 

Hereby you can find my sample data I used.

Date
1/03/2018
2/03/2018
3/03/2018
4/03/2018
5/03/2018
6/03/2018
7/03/2018
8/03/2018
9/03/2018
10/03/2018
11/03/2018
12/03/2018
13/03/2018
14/03/2018
15/03/2018
16/03/2018
17/03/2018
18/03/2018
19/03/2018
20/03/2018
21/03/2018
22/03/2018
23/03/2018
24/03/2018
25/03/2018
26/03/2018
27/03/2018
28/03/2018
29/03/2018
30/03/2018
31/03/2018
1/04/2018
2/04/2018
3/04/2018
4/04/2018
5/04/2018
6/04/2018
7/04/2018
8/04/2018
9/04/2018
10/04/2018
11/04/2018
12/04/2018
13/04/2018
14/04/2018
15/04/2018
16/04/2018
17/04/2018
18/04/2018
19/04/2018
20/04/2018
21/04/2018
22/04/2018
23/04/2018
24/04/2018
25/04/2018
26/04/2018
27/04/2018
28/04/2018
29/04/2018
30/04/2018
Closing Date,Currency,Rate
31/03/2018,USD,1
31/03/2018,EUR,1.2
31/03/2018,ZAR,4
31/03/2018,AED,1.15
30/04/2018,USD,1
30/04/2018,EUR,1.3
30/04/2018,ZAR,3.75
30/04/2018,AED,1.1
Closing date,Amount,Currency
31/03/2018,100,USD
31/03/2018,500,EUR
31/03/2018,150,ZAR
31/03/2018,200,AED
30/04/2018,400,USD
30/04/2018,215,EUR
30/04/2018,1000,ZAR

Best regards,

Thomas

@Manuchar

 

Let's try this then

 

Total Sales USD =
CALCULATE (
    SUMX (
        Sales;
        Sales[Amount]
            * CALCULATE (
                VALUES ( Rate[Rate] );
                TOPN (
                    1;
                    CALCULATETABLE ( Rate; FILTER ( Rate; Rate[Currency] = Sales[Currency] ) );
                    Rate[Closing Date]; DESC
                )
            )
    );
    DATESYTD ( 'Date'[Date] )
)

@AlB

 

Thank you so much, this is what I was looking for.

 

Br

Thomas

@Manuchar

Cool. Glad it helped.

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.