Forum Discussion

ScR's avatar
ScR
Frequent Visitor
9 years ago
Solved

Many to one currency conversion

I am in need of some guidance. I am looking to creating a Many-to-One conversion for our sales reports but I can´t seem to get it right. I am way out of my depth here but I would love to get some ...
  • kschaefers's avatar
    kschaefers
    9 years ago

    This, although it may seem simple is a considerably more difficult task.

     

    You can use this formula:

     

    Total (Base Currency) =
     (
        SUMX (
            Sales,
            VAR current_date = Sales[Date]
            RETURN
                Sales[Amount]
                    * CALCULATE (
                        CALCULATE (
                            VALUES ( dimExchange[Exchange Rate] ),
                            LASTDATE ( dimExchange[Date Key] )
                        ),
                        FILTER ( ALL ( dimCalendar ), dimCalendar[Date Key] <= current_date )
                    )
        )
    )

    As you can see this is significantly more difficult than the other solution :)

    The code basically iterates through each row of the Sales table, transforms the Row Context into a filter context (to filter the Currency on the DimExchange Table) and then modifies the dimCalendar filter to select all dates prior to the current date (in the iterated Sales table row). Finally it chooses the last date available for the given Filter set from the DimExchange table.

     

    It took me a while to wrap my head around the whole Filter and Row Context topic as well as context transition, and I think I am just scratching the surface, so maybe there is a more elegant solution here :)