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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
chrisyan_manalu
Helper II
Helper II

GetTotalPage by m code function (Source data is API)

 

Hi All,

 

I'm stuck right now

I have code like this to get how much the total page of this API (source data)

chrisyan_manalu_0-1658480543454.png

 

And when I try to invoke custom function, I got error like this

chrisyan_manalu_1-1658480543283.png

 

If the function running well, the output present how much the total page

 

Any solution ?

 

Please help

 

Thanks

2 REPLIES 2
chrisyan_manalu
Helper II
Helper II

Hi @m-colbert 

Here's the code 

(SelectedService as text) =>
    let
    BaseURL = "https://testing.com", //example API
    ConstantVar = "test/rest/CheckAPI/GetData?PageSize=""&PageNumber=""&Building=""&Category=""&Location=""&Status=""&StartDate=""&EndDate=""&StartTime={StartTime}&EndTime=", // example var
    StartDate = "2021-10-19",
    CurrentYear = Text.End("0000" & Number.ToText(Date.Year(Date.From(DateTime.LocalNow()))),4),
    CurrentMonth = Text.End("00" & Number.ToText(Date.Month(Date.From(DateTime.LocalNow()))),2),
    CurrentDay = Text.End("00" & Number.ToText(Date.Day(Date.From(DateTime.LocalNow()))),2),
    EndDate = CurrentYear & "-" & CurrentMonth & "-" & CurrentDay,
    response = Web.Contents(
    #"BaseURL",
    [
        Headers = 
        [
            Authorization= "test test" // username and pass (basic auth)
        ],
        RelativePath = #"ConstantVar" & SelectedService,
        Query = 
        [
            start_dt = StartDate,
            end_dt = EndDate,
            page = Number.ToText(1)
        ]
    ]
),
    jsonResponse = Json.Document(response),
    #"Converted to table" = Record.ToTable(jsonResponse),
    #"Filtered rows" = Table.SelectRows(#"Converted to table", each ([Name] = "total_page")),
    #"Removed columns" = Table.RemoveColumns(#"Filtered rows", {"Name"}),
    #"Changed column type" = Table.TransformColumnTypes(#"Removed columns", {{"Value", Int64.Type}}),
    #"Renamed columns" = Table.RenameColumns(#"Changed column type", {{"Value", "TotalPage"}})
in
    #"Renamed columns"

 

Thaks

m-colbert
Resolver III
Resolver III

Hi @chrisyan_manalu 

Need some addtional information to help. Can you possibly paste the code in text, I am unable to see it, too small. Also, click on the error and paste in what the error text is. 

Thanks

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.