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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MarcF
Frequent Visitor

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.

1 ACCEPTED SOLUTION
Eric_Zhang
Employee
Employee

@MarcF

 

Supposing the dataset is as below.

 

Capture.PNG

 

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 )
    )

 Capture.PNG

 

 

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

View solution in original post

4 REPLIES 4
Eric_Zhang
Employee
Employee

@MarcF

 

Supposing the dataset is as below.

 

Capture.PNG

 

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 )
    )

 Capture.PNG

 

 

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

@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.

@Eric_Zhang,

Had a similar problem and your solution helped solve it.

Great work.

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?

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.