Thursday, December 10, 2020

Power Query - SubQuery LastTime by Category

    //Sub Query LastTime by Category 

    Grouped = Table.Group(#"Removed Columns", {"Acao"}, {{"AllData", each _, type table}, {"MaxUpdated", each List.Max([Updated]), type datetime}}),

    SelectedMax = Table.AddColumn(Grouped, "Custom", (x) => Table.SelectRows(x[AllData], each [Updated] = x[Updated] & [Acao] = x[Acao])),

    RemovedColumns = Table.RemoveColumns(SelectedMax,{"Custom", "Acao"}),

    #"Expanded AllData1" = Table.ExpandTableColumn(RemovedColumns, "AllData", {"Date", "Open", "High", "Low", "Close", "Volume", "Acao", "Updated", "volume_adi", "volume_obv", "volume_cmf", "volume_fi", "volume_mfi", "volume_em", "volume_sma_em", "volume_vpt", "momentum_kama", "momentum_roc", "momentum_ppo", "momentum_ppo_signal", "momentum_ppo_hist", "others_dr", "others_dlr", "File", ".Index", ".PK_Acao_Date"}),

    #"Added Custom3" = Table.AddColumn(#"Expanded AllData1", "Val", each if [MaxUpdated] = [Updated] then 1 else 0),

    TableUpdate = Table.SelectRows(#"Added Custom3", each ([Val] = 1)),

Wednesday, December 9, 2020

DAX - SWITCH / Case

.Class = SWITCH ( TRUE (); ISERROR ( FIND ( "2021"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Online"; ISERROR ( FIND ( "2018"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Legacy"; ISERROR ( FIND ( "2019"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Legacy"; ISERROR ( FIND ( "2020"; DIM_directoriesW[FolderFirst2] ) ) <> TRUE (); "Legacy"; ISERROR ( FIND ( "..."; DIM_directoriesW[FolderFirst2]) ) = TRUE () && ISERROR ( FIND ( "BAG"; DIM_directoriesW[FolderFirst2] ) ) = TRUE (); "???" ) Case1 = IF( SELECTEDVALUE(DimCustomer[EnglishEducation])="Bachelors", "Green", "White") Case2 = SWITCH( SELECTEDVALUE(DimCustomer[EnglishEducation]), "Bachelors","Green", "High School","Red", "Partial High School","Tan", "Graduate Degree","Yellow", "White" ) IF ( [A] > [B], "First case", IF ( [A] = [B], "Second case", IF ( [A] = 0, "Third case", "Fourth case" ) ) ) Case3 = SWITCH( TRUE(), [Sales]>8000000,"Green", [Sales]>5000000,"Tan", [Sales]>3000000,"Yellow", [Sales]<2000000,"Red", "White" ) -- Using SWITCH the first condition met defines the result. -- In the following example, the second condition (<= 150) will never be -- met, because the first one is less restrictive. DEFINE MEASURE Sales[Discounted Sales] = SUMX ( SUMMARIZE ( Sales, Sales[Net Price], Product[Category] ), VAR DiscountPct = SWITCH ( TRUE, Sales[Net Price] <= 1000, 0.2, Sales[Net Price] <= 150, 0.15, Product[Category] = "Audio", 0.13, 0 ) RETURN [Sales Amount] * (1 - DiscountPct ) ) EVALUATE SUMMARIZECOLUMNS ( 'Product'[Category], "Sales Amount", [Sales Amount], "Discounted sales", [Discounted Sales] ) ORDER BY [Category]

Saturday, December 5, 2020

Power Query & Python - Loader Data

 let

    Source = Python.Execute("import pandas as pd#(lf)import investpy#(lf)data = [['brazil','AstraZeneca PLC','AstraZeneca PLC','.'   , 'BRL'   ,'A1ZN34' ] ]#(lf)data = pd.DataFrame(data,columns=['country',  'name',  'full_name',  'isin',  'currency',  'symbol'])#(lf)df_stocks = investpy.get_stocks(country='Brazil')#(lf)df_stocks = df_stocks.append([data], sort=False)#(lf)dataset = df_stocks"),

    dataset1 = Source{[Name="dataset"]}[Value]

in

    dataset1



Python Code:

import pandas as pd

import investpy

data = [['brazil','AstraZeneca PLC','AstraZeneca PLC','.'   , 'BRL'   ,'A1ZN34' ] ]

data = pd.DataFrame(data,columns=['country',  'name',  'full_name',  'isin',  'currency',  'symbol'])

df_stocks = investpy.get_stocks(country='Brazil')

df_stocks = df_stocks.append([data], sort=False)

dataset = df_stocks

Power BI APP - Delete or Unpublish

 UNPUBLISH DELETE