Forum Discussion

zjdaher's avatar
zjdaher
Frequent Visitor
3 years ago
Solved

Convert Sales from local currency to Dollar with missing dates

Hello, i am new to power BI and would need some help with the below. when the user click on the dollar slicer we need to convert our sales from local currency to Dollar currency based on the sales ...
  • zjdaher's avatar
    3 years ago

    hello, i ended up repopulating the exchange table with missing dates, with rate of missing dates taking the value of previous date. the exchange table looks like this now:

     

    with tmp(plant_date) as
    (
    select cast('20210101' as datetime)
    union all
    select plant_date + 1
    from tmp
    where plant_date < '20301231'
    )

    select 'US2' as [Currency Code],dt as [Starting Date],max([Relational Exch_ Rate Amount]) over (partition by grp) [Relational Exch_ Rate Amount]
    from
    (
    select coalesce([Starting Date],plant_date) dt,[Relational Exch_ Rate Amount],
    SUM(CASE WHEN [Relational Exch_ Rate Amount] IS NOT NULL THEN 1 ELSE 0 END) OVER(
    ORDER BY plant_date
    ROWS UNBOUNDED PRECEDING) grp
    from tmp left join (select [Currency Code],[Starting Date],[Relational Exch_ Rate Amount]
    from Till.dbo.[UCCM$Currency Exchange Rate] where [Currency Code]='US2')
    #t on tmp.plant_date=#t.[Starting Date]
    ) as der
    option (maxrecursion 0)