How can we use Ceiling function functionality in ADF Expression ( without using DataFlow)

Tyagi, Varun (Slalom Consulting) 26 Reputation points
2022-09-01T15:46:23.163+00:00

I have to calculate the number of search Pages from the API response and results per page are 25. Hence, if total results available are 220, then I have to do iterate for 9 times, 220/25 = 8.08, hence I need a ceiling function in ADF expression

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
{count} votes

Accepted answer
  1. MartinJaffer-MSFT 26,236 Reputation points
    2022-09-02T21:36:00.727+00:00

    Hello @Tyagi, Varun (Slalom Consulting) ,
    Thanks for the question and using MS Q&A platform.

    As I understand the ask is for a way to determine whether you need to add an extra page in your pagination for remainder given number of records, and number of records per page.

    While there is no ceiling function, there is modulo function.
    The modulo function gets the remainder of integer division.

    mod(4,2) => 0    div(4,2) => 2    div(4.0,2) => 2.0  
    mod(5,2) => 1    div(5,2) => 2    div(4.0,2) => 2.5  
    mod(220,25) => 20  
    

    So when the remainder is more than 0, then you need another page.

    Returns true when needs another page  
    
    @greater( mod(num_records, 25) , 0 )  
    

    Put all together (assuming you are using ints not floats) , replace 200 with your input

    @{  
        if(  
            greater(  
                mod(220,25),  
                0  
            ),  
            add(1, div(220,25) ),  
            div(220,25)  
        )  
    }  
    

    The difficulty I ran into earlier, was the failure of int(2.5) . I expected this to result in 2, but got error instead. Since I can't use this, I will have to do string operations if you really need ceiling for some reason.

    @{  
        if(  
            greater(  
                length(split(pipeline().parameters.IN2,'.')),1)  
            ,  
            if(greater(int(split(pipeline().parameters.IN2,'.')[1]),0)  
            , add(int(split(pipeline().parameters.IN2,'.')[0]),1),  
             split(pipeline().parameters.IN2,'.')[0])  
            ,  
            pipeline().parameters.IN2  
        )  
    }  
    

    Please do let me if you have any queries.

    Thanks
    Martin


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
      • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Tyagi, Varun (Slalom Consulting) 26 Reputation points
    2022-09-06T19:20:38.897+00:00

    Thanks Martin,

    I did something similar to resolve the issue, used mod function. Used mod in if statement and increased the number to plus one if mod result != 0

    @if(equals(mod(Int(variables('TotalResultsAvailable')),25),0),string(div(Int(variables('TotalResultsAvailable')),25)),string(add(div(Int(variables('TotalResultsAvailable')),25),1)))

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.