Wednesday, March 29, 2023

DAX - Comparação de informações entre 2 tabelas (PROCV)

.Vlr_PF_Diff =

CALCULATE ( SUMX ( Table01, Table01[Valor_Compara01] - CALCULATE ( SUMX ( RELATEDTABLE ( Table02 ), (Table02[Valor_Compara02] )), FILTER ( Table02 , AND(Table02[Var_A] = Table01[Var_A], AND(Table02[Var_B] = Table01[Var_B] , Table02[Var_C] = Table01[Var_C] )) ) ) ) )

Wednesday, March 22, 2023

Postgres SQL - AWS Connect

 To disable encryption

  1. File --> Options and settings --> Data source settings
  2. Click Edit Permissions on your connection
  3. Uncheck Encrypt Connections
==================================================

Power Query:
let
    Source = Value.NativeQuery(PostgreSQL.Database("database.XPTO.com.br", "DBName", [CreateNavigationProperties=false]),
"select#(lf)  table_name,#(lf)  pg_size_pretty(pg_relation_size(quote_ident(table_name))),#(lf)  pg_relation_size(quote_ident(table_name))#(lf)from information_schema.tables#(lf)where table_schema = 'public'#(lf)order by 3 desc", null, [EnableFolding=true])
in
    Source


=============================
select
  table_name,
  pg_size_pretty(pg_relation_size(quote_ident(table_name))),
  pg_relation_size(quote_ident(table_name))
from information_schema.tables
where table_schema = 'public'
order by 3 desc;

select table_schema, table_name, pg_relation_size('"'||table_schema||'"."'||table_name||'"')
from information_schema.tables
order by 3

DAX - Running total based on ranking index - Acumulado Ranking

Rank = 


RANKX (

    SUMMARIZE (

        ALLSELECTED ( FAT_TABLE ),

        FAT_TABLE[YYYYMM],

        FAT_TABLE[VAR1]

    ),

    CALCULATE ( SUM ( FAT_TABLE[Price (€/t)] ) ),

    ,

    ASC,

    DENSE

)

=============================================== 


Running VAR_Sum = 

IF (

    ISINSCOPE ( FAT_TABLE[VAR1] ) && ISINSCOPE ( FAT_TABLE[YYYYMM] ),

    VAR CurrentRank = [Rank]

    VAR SummarizeFAT_TABLE =

        CALCULATETABLE (

            SUMMARIZE ( FAT_TABLE, FAT_TABLE[VAR1], FAT_TABLE[YYYYMM] ),

            ALLSELECTED ( FAT_TABLE )

        )

    VAR FAT_TABLESales =

        ADDCOLUMNS ( SummarizeFAT_TABLE, "@TotalSum", [VAR_Sum], "@Rank", [Rank] )

    VAR Result =

        SUMX ( FILTER ( FAT_TABLESales, [@Rank] <= CurrentRank ), [@TotalSum] )

    RETURN

        Result

)

=============================================== 


Power BI APP - Delete or Unpublish

 UNPUBLISH DELETE