> For the complete documentation index, see [llms.txt](https://pathta.gitbook.io/pathta-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pathta.gitbook.io/pathta-docs/pathta-documentation/reporting/consultez-vos-donnees-dans-power-bi-grace-a-la-fonction-pathta/installation-de-la-fonction-pathta-pbi.md).

# Installation de la fonction Pathta PBI

{% embed url="<https://www.tella.tv/video/install-pathta-power-bi-function-hfsb>" %}

Ouvrez Power BI et ajoutez une source de données de requête vide. Copiez-collez le code M suivant dans l'éditeur avancé

<figure><img src="https://content.gitbook.com/content/tnxQfZHdgYjWlKoRKSKC/blobs/McVuTsusHNHlVbwk1RTj/image.png" alt=""><figcaption></figcaption></figure>

```powerquery
let
    PathtaFx = (PathId as number) as table =>
    let
        BaseUrl = "https://reporting.pathta.io/Reporting/",
        CredParamName = "credential",
        FieldsJson = Json.Document(
            Web.Contents(
                BaseUrl,
                [
                    RelativePath = Number.ToText(PathId) & "/PathFields",
                    ApiKeyName = CredParamName,
                    Headers=[Accept="application/json"]
                ]
            )
        ),
        FieldsTbl = Table.FromRecords(FieldsJson),
        FieldsRen = Table.RenameColumns(FieldsTbl, {{"id","FieldId"},{"name","FieldName"},{"type","FieldType"}}, MissingField.UseNull),

        FieldIds   = List.Transform(FieldsRen[FieldId], each Text.From(_, "en-US")),
        FieldNames = FieldsRen[FieldName],

        TypeMapping = (t as text) as type =>
            if      t = "String"        then type text
            else if t = "Int32"         then type number
            else if t = "Int64"         then type number
            else if t = "Decimal"       then type number
            else if t = "Boolean"       then type logical
            else if t = "DateTime"      then type datetime
            else if t = "Date"          then type date
            else if t = "StringArray"   then type list
            else if t = "MultipleLinks" then type list
            else if t = "SimpleLink"    then type text
            else type any,

        FieldTypes = List.Transform(FieldsRen[FieldType], each TypeMapping(_)),

        RenamePairs = List.Zip({FieldIds, FieldNames}),
        FieldsZipped = List.Zip({FieldNames, FieldTypes}),
        ListCols = List.Select(FieldsZipped, each _{1} = type list),
        NonListCols = List.Select(FieldsZipped, each _{1} <> type list),
        NonListTypePairs = List.Transform(NonListCols, each { _{0}, _{1} }),

        FieldIdParam = Text.Combine(FieldIds, ";"),
        FirstUrl = Number.ToText(PathId) & "/PathRows?" & "fieldIds=" & FieldIdParam,

        GetPage = (Url as text) as table =>
            let
                Resp = Json.Document(Web.Contents(BaseUrl,
                [
                    RelativePath = Url,
                    ApiKeyName = CredParamName,
                    Headers=[Accept="application/json"]
                ])),
                Rows = try Resp[Rows] otherwise {},
                T0 = Table.FromList(Rows, Splitter.SplitByNothing(), {"Data"}),
                T1 = if Table.RowCount(T0) = 0 then #table(FieldNames,{}) else Table.ExpandRecordColumn(T0, "Data", FieldIds, FieldIds),
                T2 = Table.RenameColumns(T1, RenamePairs, MissingField.Ignore),
                T3 = List.Accumulate(
                        ListCols,
                        T2,
                        (s, c) => Table.TransformColumns(s, {{c{0}, each if _ = null then {} else _}})
                     ),
                T4 = Table.TransformColumnTypes(T3, NonListTypePairs),
                NextLink =
                    if Record.HasFields(Resp, "PageKey") and Resp[PageKey] <> null and Resp[PageKey] <> "" then
                        Number.ToText(PathId) & "/PathRows?" & "fieldIds=" & FieldIdParam &
                        (if Record.HasFields(Resp, "TaskId") then "&taskId=" & Text.From(Resp[TaskId]) else "") &
                        "&pageKey=" & Text.From(Resp[PageKey])
                    else
                        null,
                Out = T4 meta [NextLink = NextLink]
            in
                Out,

        Pages = List.Generate(
            ()=> [Tbl = GetPage(FirstUrl)],
            each [Tbl] <> null,
            each
                let nxt = Value.Metadata([Tbl])[NextLink]? in [Tbl = if nxt <> null then GetPage(nxt) else null],
            each [Tbl]
        ),

        Combined = if List.Count(Pages) = 0 then #table(FieldNames,{}) else Table.Combine(Pages)
    in
        Combined
in
    PathtaFx
```

Lors de la première utilisation de la fonction, vous devez saisir le jeton d'authentification généré par Pathta.

Saisissez la valeur du paramètre PathId, puis cliquez sur « Invoke ».

{% hint style="info" %}
Vous trouverez ici comment trouver votre PathId :

[Rechercher un PathId : identifiant de rapport de chemin d'accès](/pathta-docs/pathta-documentation/reporting/consultez-vos-donnees-dans-power-bi-grace-a-la-fonction-pathta/rechercher-un-pathid-identifiant-de-rapport-de-chemin-dacces.md)
{% endhint %}

<figure><img src="https://content.gitbook.com/content/tnxQfZHdgYjWlKoRKSKC/blobs/gKRzTk6DlPhv7rjtVgT2/image.png" alt=""><figcaption></figcaption></figure>

Cliquez sur « Modifier les identifiants »

<figure><img src="https://content.gitbook.com/content/tnxQfZHdgYjWlKoRKSKC/blobs/vEpIy3rd71agDi253WGe/image.png" alt=""><figcaption></figcaption></figure>

Sélectionnez « Web API », collez votre jeton (copié depuis l'onglet « Vérification » d'un chemin de rapport) dans le champ « Clé », puis cliquez sur « Se connecter ».

<figure><img src="https://content.gitbook.com/content/tnxQfZHdgYjWlKoRKSKC/blobs/p1QtT93xel5CYr1JUOMe/image.png" alt=""><figcaption></figcaption></figure>

Cliquez sur « Continuer »

<figure><img src="https://content.gitbook.com/content/tnxQfZHdgYjWlKoRKSKC/blobs/hYuaPSxfiVAzbtKnq39z/image.png" alt=""><figcaption></figcaption></figure>

Définissez le niveau de confidentialité sur « Organisation » et cliquez sur « Enregistrer ».

<figure><img src="https://content.gitbook.com/content/tnxQfZHdgYjWlKoRKSKC/blobs/MEGpWm7KWMA6o8cd3tpV/image.png" alt=""><figcaption></figcaption></figure>

{% hint style="success" %}
Votre fonction est désormais prête à être utilisée !
{% endhint %}
