Thursday, May 13, 2021

DAX - CALCULATE Actualized vs. Planned

Measure:
 .Inflation_PLAN = CALCULATE(DIM_Prem_Plan[.Vlr_Inflation_PLAN], FILTER(DIM_Prem_Plan, DIM_Prem_Plan[PK_Plan]IN VALUES(FAT_DB[PK_Plan])))


Tuesday, May 11, 2021

Power Query - Connect API REST API Bearer

 

FNC_Access_Token

() => 

let

    url = "https://XPTO_SITE_TOKEN",

    body  = "{ ""user"": ""XPTO_USER"", ""pwd"": ""XPTO_PASS""} ",

    AccessToken = Json.Document(Web.Contents(url, [Headers=[#"Content-Type"="application/json"], Content=Text.ToBinary(body)])),

    access_token = AccessToken[token]

in

    access_token


FNC_Table_Prep

let

  // Get_Data

  Query = () => let

    Source = Json.Document(Web.Contents("XPTO_SITE_SEARCH", [Headers=[Authorization="Bearer " & Fnc_Access_Token()]])),

    #"Converted to Table" = Record.ToTable(Source),

    Value = #"Converted to Table"{4}[Value]

in

    Value

in

  Query


DIM_Table

let

    Source = Fnc_Table_Prep(),

    #"Converted to Table" = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),

    #"Expanded Column1" = Table.ExpandRecordColumn(#"Converted to Table", "Column1", {"_id", "user", "phone", "profile", "hLastUpdate", "active", "activationCode", "userName", "birthday", "gender", "followingCategories", "isProfileComplete", "name", "dob"}, {"_id", "user", "phone", "profile", "hLastUpdate", "active", "activationCode", "userName", "birthday", "gender", "followingCategories", "isProfileComplete", "name", "dob"})

in

    #"Expanded Column1"


Monday, May 10, 2021

Power Query - Block IF THEN ELSE

 let

    Source = (ano as text) => let 

    

        EmptyTable = #table({"/BIC/ZMATERIAL",...}, {}),

        Source = PowerBI.Dataflows(null),


        //THEN

        WorkspacePRO = Source{[workspaceId="564564563466353653665"]}[Data],

        DataflowPRO = WorkspacePRO{[dataflowName=Text.Combine({"MIX_Full_", ano})]}[Data],

        FAT_PricesPRO = DataflowPRO{[entity=Text.Combine({"MIX_FullDetail_", ano})]}[Data],

    

        //ELSE

        WorkspacePPU = Source{[workspaceId="356633456346456456456"]}[Data],

        DataflowPPU = WorkspacePPU{[dataflowName=Text.Combine({"MIX_Full_", ano})]}[Data],

        FAT_PricesPPU = DataflowPPU{[entity=Text.Combine({"MIX_FullDetail_", ano})]}[Data],


        Final_Table = if PRO_PPU = "PRO" then 

        FAT_PricesPRO else 

        FAT_PricesPPU,

        

        Final_Table2 = try Final_Table otherwise EmptyTable

    in 

        Final_Table2

in

    Source

Power Query - Connect Onedrive

 let

Source = SharePoint.Files("https://XXX.sharepoint.com/personal/XXX_com/", [ApiVersion = 15]),
#"Linhas Filtradas" = Table.SelectRows(Source, each Text.Contains([Folder Path], "XPTO_FOLDER")),
Step2 = Table.SelectColumns(#"Linhas Filtradas", {"Content"}),
Step3 = Table.AddColumn(Step2, "Cols", each Excel.Workbook([Content])),
Step4 = Table.RemoveColumns(Step3, {"Content"}),
Step5 = Table.ExpandTableColumn(Step4, "Cols", {"Name", "Data", "Item", "Kind", "Hidden"}, {"Name", "Data", "Item", "Kind", "Hidden"}),
#"Linhas Filtradas1" = Table.SelectRows(Step5, each ([Kind] = "Sheet")),
#"Linhas Filtradas2" = Table.SelectRows(#"Linhas Filtradas1", each [Name] = "Dados"),
Step7 = Table.RemoveColumns(#"Linhas Filtradas2", {"Item", "Kind", "Hidden", "Name"}),
#"Data Expandida" = Table.ExpandTableColumn(Step7, "Data", {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13"}, {"Column1", "Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10", "Column11", "Column12", "Column13"})
in
#"Data Expandida"

Power BI APP - Delete or Unpublish

 UNPUBLISH DELETE