Forum Discussion

MarcF's avatar
MarcF
Icon for Advocate IV rankAdvocate IV
10 years ago
Solved

Best way to fix missing days for currency conversion API

Hi all,

 

I am looking for a best practice to fill missing days with my €/£ Quandl currency conversion API. The API feeds in currecny conversion for week days but returns null values during weekends and holdays. At the moment I have created a column which replaces the null values with the historical average rate:

 

Currency = IF(ISBLANK(calculate(sum(EURvsGBP[Value]))),average(EURvsGBP[Value]), calculate(sum(EURvsGBP[Value])))

 

Is there any better way of doing this? Ideally I would want a) the average to be weekly based, or b) replace the null values with the previous non-null.

 

Thank you.

  • MarcF

     

    Supposing the dataset is as below.

     

     

    Check a measure as

     

    Currency = 
    VAR lastNoBlankValDate =
        MAXX (
            FILTER (
                ALL ( EURvsGBP ),
                EURvsGBP[DATE] <= MAX ( EURvsGBP[DATE] )
                    && EURvsGBP[VALUE] <> BLANK ()
            ),
            EURvsGBP[DATE]
        )
    RETURN
        CALCULATE (
            SUM ( EURvsGBP[VALUE] ),
            FILTER ( ALL ( EURvsGBP ), EURvsGBP[DATE] = lastNoBlankValDate )
        )

     

     

     

    Regarding week-based, check if Week-Based Time Intelligence in DAX helps.

4 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Icon for Microsoft Employee rankMicrosoft Employee

    MarcF

     

    Supposing the dataset is as below.

     

     

    Check a measure as

     

    Currency = 
    VAR lastNoBlankValDate =
        MAXX (
            FILTER (
                ALL ( EURvsGBP ),
                EURvsGBP[DATE] <= MAX ( EURvsGBP[DATE] )
                    && EURvsGBP[VALUE] <> BLANK ()
            ),
            EURvsGBP[DATE]
        )
    RETURN
        CALCULATE (
            SUM ( EURvsGBP[VALUE] ),
            FILTER ( ALL ( EURvsGBP ), EURvsGBP[DATE] = lastNoBlankValDate )
        )

     

     

     

    Regarding week-based, check if Week-Based Time Intelligence in DAX helps.

    • MarcF's avatar
      MarcF
      Icon for Advocate IV rankAdvocate IV

      Thanks, that works just great! I was wondering now what is the best database modelling practice for currency conversion data. At the moment I have three tables linked by 'Date':

       

      CurrencyTable --- DateTable --- Sales

       

      I have created a currency column in the DataTable with the exchange rate for the missing dates (as the CurrencyTable has no dates for weekends and bank holidays) and call it back in the sales table through a lookup. Is there a better way to do this?

    • anandav's avatar
      anandav
      Icon for Skilled Sharer rankSkilled Sharer

      Eric_Zhang,

       

      How can this be achieved in a calculated column?

       

      The measure is working but I am trying to create a calculated column to fill the missing values.

       

      Any help will be appreciated.