Forum Discussion

ncbshiva's avatar
ncbshiva
Icon for Advocate V rankAdvocate V
7 years ago
Solved

Dynamically changing the source from local files to Sharepoint using Parameter

Hi Team,   Is it possible to create a parameter in Power BI , that swichtes the source between the local files and the same files stored in the sharepoint. If possible please let me know how to cre...
  • v-danhe-msft's avatar
    7 years ago

    Hi ncbshiva,

    Based on my test, you could refer to below steps in query editor:

    Open the Advanced language and enter below code:

    (para as number) =>
    if para=1
    then
    let
        Source = Excel.Workbook(Web.Contents("your sharepoint address"), null, true),
        Talk_Sheet = Source{[Item="Talk",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Talk_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Full date", type date}, {"sale", Int64.Type}})
    in
        #"Changed Type"
    else 
    let
        Source = Excel.Workbook(File.Contents("your local file address"), null, true),
        Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
        #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Full date", type date}, {"sale", Int64.Type}})
    in
       #"Changed Type"

    If you enter the number 1, it will load the data in your sharepoint:

    If you enter the number 2, it will load the data in your local file:

     

    Regards,

    Daniel He