├── TMDL ├── Pasta Medidas ├── Grupos de Cálculo └── dCalendario ├── Formato Decimal para Hora ├── CalendarioHoras ├── Formato Dinâmico DAX └── dCalendario /TMDL/Pasta Medidas: -------------------------------------------------------------------------------- 1 | createOrReplace 2 | 3 | table Measure 4 | 5 | measure 'Medida Exemplo' = NOW() 6 | formatString: General Date 7 | 8 | column value 9 | isHidden 10 | summarizeBy: sum 11 | isNameInferred 12 | sourceColumn: [Value] 13 | 14 | partition Measure = calculated 15 | mode: import 16 | source = {BLANK()} 17 | -------------------------------------------------------------------------------- /Formato Decimal para Hora: -------------------------------------------------------------------------------- 1 | VAR _Valor = SELECTEDMEASURE() 2 | VAR _Hora = TRUNC ( _Valor ) 3 | VAR _MinutoDecimal = ( _Valor - _Hora) * 60 4 | VAR _Minuto = TRUNC ( ( _Valor - _Hora) * 60 ) 5 | VAR _Segundos = TRUNC ( ( _MinutoDecimal - _Minuto ) * 60 ) 6 | RETURN 7 | """" & FORMAT ( _Hora, "0#;0#" ) 8 | & ":" 9 | & FORMAT ( _Minuto, "0#;0#" ) 10 | & ":" 11 | & FORMAT ( _Segundos, "0#;0#" ) 12 | & """" 13 | -------------------------------------------------------------------------------- /CalendarioHoras: -------------------------------------------------------------------------------- 1 | let 2 | Horas = List.Times(#time(0,0,0),24*60*60,#duration(0,0,0,1)), 3 | Tabela = #table( 4 | type table[ 5 | Horas = time, 6 | Hora = Int64.Type, 7 | Minutos = Int64.Type, 8 | Segundos = Int64.Type, 9 | Hora Completa = text 10 | 11 | 12 | ], 13 | List.Transform( 14 | Horas, 15 | each { 16 | _, 17 | Time.Hour(_), 18 | Time.Minute(_), 19 | Time.Second(_), 20 | Text.PadStart(Text.From(Time.StartOfHour(_)),5) 21 | 22 | } 23 | 24 | ) 25 | ) 26 | in 27 | Tabela 28 | -------------------------------------------------------------------------------- /Formato Dinâmico DAX: -------------------------------------------------------------------------------- 1 | VAR _Valor = SELECTEDMEASURE() 2 | VAR _Formato = 3 | SWITCH(TRUE(), 4 | _Valor <= -1000000000, "R$ #,#0,,,.00B; R$ #,#0,,,.0B", 5 | _Valor <= -1000000, "R$ #,#0,,.00M;R$ #,#0,,.0M", 6 | _Valor <= -1000, "R$ #,#0,.00K;R$ #,#0,.0K", 7 | _Valor >= 1000000000, "R$ #,#0,,,.0B", 8 | _Valor >= 1000000, "R$ #,#0,,.0M", 9 | _Valor >= 1000, "R$ #,#0,.0K", 10 | "R$ #,0.00;R$ #,0.00") 11 | RETURN 12 | """"&FORMAT(SELECTEDMEASURE(),_Formato)&"""" &"" 13 | 14 | 15 | 16 | 17 | VAR _Valor = SELECTEDMEASURE() 18 | VAR _Meta = [Atingimento Meta] 19 | VAR _Formato = 20 | SWITCH(TRUE(), 21 | _Valor <= -1000000000, "R$ #,#0,,,.00B; R$ #,#0,,,.0B", 22 | _Valor <= -1000000, "R$ #,#0,,.00M;R$ #,#0,,.0M", 23 | _Valor <= -1000, "R$ #,#0,.00K;R$ #,#0,.0K", 24 | _Valor >= 1000000000, "R$ #,#0,,,.0B", 25 | _Valor >= 1000000, "R$ #,#0,,.0M", 26 | _Valor >= 1000, "R$ #,#0,.0K", 27 | "R$ #,0.00;R$ #,0.00") 28 | VAR _Icone = 29 | IF( _Meta >= 1, " ⇡", " ⇣") 30 | RETURN 31 | """" & FORMAT(_Valor, _Formato) & """" & 32 | """" & FORMAT(_Meta, " | 0%") & """" & 33 | _Icone 34 | -------------------------------------------------------------------------------- /TMDL/Grupos de Cálculo: -------------------------------------------------------------------------------- 1 | createOrReplace 2 | 3 | table 'Inteligencia Temporal' 4 | 5 | calculationGroup 6 | precedence: 1 7 | 8 | calculationItem Current = SELECTEDMEASURE() 9 | 10 | calculationItem AnoAnterior = 11 | CALCULATE ( 12 | SELECTEDMEASURE (), 13 | SAMEPERIODLASTYEAR ( 'dCalendario'[Data] ) 14 | ) 15 | 16 | calculationItem YoY = 17 | VAR _Atual = SELECTEDMEASURE () 18 | VAR _LY = 19 | CALCULATE ( 20 | SELECTEDMEASURE (), 21 | SAMEPERIODLASTYEAR ( 'dCalendario'[Data] ) 22 | ) 23 | VAR _Dif = _Atual - _LY 24 | 25 | RETURN 26 | DIVIDE ( _DIF , _LY ) 27 | 28 | formatStringDefinition = "0.0%;-0.0%" 29 | 30 | calculationItem YTD = 31 | CALCULATE ( 32 | SELECTEDMEASURE (), 33 | DATESYTD ( 'dCalendario'[Data] ) 34 | ) 35 | 36 | calculationItem QTD = 37 | CALCULATE ( 38 | SELECTEDMEASURE (), 39 | DATESQTD ( 'dCalendario'[Data] ) 40 | ) 41 | 42 | calculationItem MTD = 43 | CALCULATE ( 44 | SELECTEDMEASURE (), 45 | DATESMTD ( 'dCalendario'[Data] ) 46 | ) 47 | 48 | column 'Exibir Como' 49 | dataType: string 50 | sourceColumn: Name 51 | sortByColumn: Ordinal 52 | 53 | column Ordinal 54 | dataType: int64 55 | formatString: 0 56 | summarizeBy: none 57 | sourceColumn: Ordinal 58 | -------------------------------------------------------------------------------- /dCalendario: -------------------------------------------------------------------------------- 1 | let 2 | 3 | //Alterar somente a Tabela e a coluna de Datas 4 | // Você pode deixar a a data inicial fixa alterando DataInicio para DataInicio = #date(2019,01,01) e alterar somente o ano que deseja. 5 | // A Maior data você pode deixar dinâmico conforme o ano atual, mudando DataFim = Date.EndOfYear(MaiorData), para DataFim = Date.From(Date.EndOfYear(DateTime.LocalNow()) 6 | // Caso utilize as opções acima, pode comentar o parâmetro Datas, MenorData e MaiorData 7 | 8 | 9 | 10 | 11 | MenorData = #date(2021,01,01), 12 | MaiorData = Date.From(Date.EndOfYear(DateTime.LocalNow())), 13 | DataInicio = Date.StartOfYear(MenorData), 14 | DataFim = Date.EndOfYear(MaiorData), 15 | Dias = Duration.Days(DataFim- DataInicio) +1, 16 | ListarDatas = List.Dates(DataInicio, Dias, #duration(1,0,0,0)), 17 | Tabela = #table( 18 | type table[ 19 | Data = date, 20 | Dia = Int64.Type, 21 | Ano = Int64.Type, 22 | NomeMes = text, 23 | MesAbre = text, 24 | MesAno = text, 25 | MesNum = number, 26 | AnoMesINT = number, 27 | Trimestre = Int64.Type, 28 | TrimestreAbreviado = text, 29 | Bimestre = text, 30 | Semestre = text, 31 | Semana = Int64.Type, 32 | DiaSemana = Int64.Type, 33 | NomeDia = text, 34 | DiaAtualTF = Logical.Type, 35 | EMesAtualTF = Logical.Type, 36 | EAnoAtualTF = Logical.Type, 37 | MesAtual = text, 38 | AnoAtual = text, 39 | Data Atual = text 40 | 41 | 42 | ], 43 | List.Transform( 44 | ListarDatas, 45 | each { 46 | _, 47 | Date.Day(_), 48 | Date.Year(_), 49 | Text.Proper( Date.MonthName(_)), 50 | Text.Proper(Text.Start(Date.MonthName(_), 3)), 51 | Text.Proper(Text.Start(Date.MonthName(_), 3)) & "-" & Text.End(Text.From(Date.Year(_)), 2), 52 | Date.Month(_), 53 | Date.Year(_) * 100 + Date.Month(_), 54 | Date.QuarterOfYear(_), 55 | Text.From(Date.QuarterOfYear(_)) & "º Trim ", 56 | Text.From( Number.RoundUp( Date.Month(_)/2,0)) & "º Bim", 57 | Text.From( Number.RoundUp( Date.Month(_)/6,0)) & "º Sem", 58 | Date.WeekOfMonth(_), 59 | Date.DayOfWeek(_), 60 | Date.DayOfWeekName(_), 61 | Date.IsInCurrentDay(_), 62 | Date.IsInCurrentMonth(_), 63 | Date.IsInCurrentYear(_), 64 | if Date.IsInCurrentMonth(_) and Date.IsInCurrentYear(_) then "Mês Atual" else Text.Proper(Text.Start(Date.MonthName(_), 3)), 65 | if Date.IsInCurrentYear(_) then "Ano Atual" else Text.From(Date.Year(_)), 66 | if Date.IsInCurrentDay(_) then "Dia Atual" else Text.From(_) 67 | 68 | 69 | } 70 | 71 | ) 72 | ) 73 | in 74 | Tabela 75 | -------------------------------------------------------------------------------- /TMDL/dCalendario: -------------------------------------------------------------------------------- 1 | createOrReplace 2 | 3 | table dCalendario 4 | dataCategory: Time 5 | 6 | column Data 7 | dataType: dateTime 8 | isKey 9 | formatString: Long Date 10 | summarizeBy: none 11 | sourceColumn: Data 12 | 13 | annotation SummarizationSetBy = Automatic 14 | 15 | annotation UnderlyingDateTimeDataType = Date 16 | 17 | column Dia 18 | dataType: int64 19 | formatString: 0 20 | summarizeBy: none 21 | sourceColumn: Dia 22 | 23 | annotation SummarizationSetBy = Automatic 24 | 25 | column Ano 26 | dataType: int64 27 | formatString: 0 28 | summarizeBy: none 29 | sourceColumn: Ano 30 | 31 | annotation SummarizationSetBy = Automatic 32 | 33 | column NomeMes 34 | dataType: string 35 | summarizeBy: none 36 | sourceColumn: NomeMes 37 | sortByColumn: MesNum 38 | 39 | changedProperty = SortByColumn 40 | 41 | annotation SummarizationSetBy = Automatic 42 | 43 | column MesAbre 44 | dataType: string 45 | summarizeBy: none 46 | sourceColumn: MesAbre 47 | sortByColumn: MesNum 48 | 49 | changedProperty = SortByColumn 50 | 51 | annotation SummarizationSetBy = Automatic 52 | 53 | column MesAno 54 | dataType: string 55 | summarizeBy: none 56 | sourceColumn: MesAno 57 | sortByColumn: AnoMesINT 58 | 59 | changedProperty = SortByColumn 60 | 61 | annotation SummarizationSetBy = Automatic 62 | 63 | column MesNum 64 | dataType: double 65 | summarizeBy: none 66 | sourceColumn: MesNum 67 | 68 | annotation SummarizationSetBy = Automatic 69 | 70 | annotation PBI_FormatHint = {"isGeneralNumber":true} 71 | 72 | column AnoMesINT 73 | dataType: double 74 | summarizeBy: none 75 | sourceColumn: AnoMesINT 76 | 77 | annotation SummarizationSetBy = Automatic 78 | 79 | annotation PBI_FormatHint = {"isGeneralNumber":true} 80 | 81 | column Trimestre 82 | dataType: int64 83 | formatString: 0 84 | summarizeBy: none 85 | sourceColumn: Trimestre 86 | 87 | annotation SummarizationSetBy = Automatic 88 | 89 | column TrimestreAbreviado 90 | dataType: string 91 | summarizeBy: none 92 | sourceColumn: TrimestreAbreviado 93 | 94 | annotation SummarizationSetBy = Automatic 95 | 96 | column Bimestre 97 | dataType: string 98 | summarizeBy: none 99 | sourceColumn: Bimestre 100 | 101 | annotation SummarizationSetBy = Automatic 102 | 103 | column Semestre 104 | dataType: string 105 | summarizeBy: none 106 | sourceColumn: Semestre 107 | 108 | annotation SummarizationSetBy = Automatic 109 | 110 | column Semana 111 | dataType: int64 112 | formatString: 0 113 | summarizeBy: none 114 | sourceColumn: Semana 115 | 116 | annotation SummarizationSetBy = Automatic 117 | 118 | column DiaSemana 119 | dataType: int64 120 | formatString: 0 121 | summarizeBy: none 122 | sourceColumn: DiaSemana 123 | 124 | annotation SummarizationSetBy = Automatic 125 | 126 | column NomeDia 127 | dataType: string 128 | summarizeBy: none 129 | sourceColumn: NomeDia 130 | 131 | annotation SummarizationSetBy = Automatic 132 | 133 | column DiaAtualTF 134 | dataType: boolean 135 | formatString: """TRUE"";""TRUE"";""FALSE""" 136 | summarizeBy: none 137 | sourceColumn: DiaAtualTF 138 | 139 | annotation SummarizationSetBy = Automatic 140 | 141 | column EMesAtualTF 142 | dataType: boolean 143 | formatString: """TRUE"";""TRUE"";""FALSE""" 144 | summarizeBy: none 145 | sourceColumn: EMesAtualTF 146 | 147 | annotation SummarizationSetBy = Automatic 148 | 149 | column EAnoAtualTF 150 | dataType: boolean 151 | formatString: """TRUE"";""TRUE"";""FALSE""" 152 | summarizeBy: none 153 | sourceColumn: EAnoAtualTF 154 | 155 | annotation SummarizationSetBy = Automatic 156 | 157 | column MesAtual 158 | dataType: string 159 | summarizeBy: none 160 | sourceColumn: MesAtual 161 | 162 | annotation SummarizationSetBy = Automatic 163 | 164 | column AnoAtual 165 | dataType: string 166 | summarizeBy: none 167 | sourceColumn: AnoAtual 168 | 169 | annotation SummarizationSetBy = Automatic 170 | 171 | partition dCalendario = m 172 | mode: import 173 | source = ``` 174 | let 175 | MenorData = #date(2021,01,01), 176 | MaiorData = Date.From(Date.EndOfYear(DateTime.LocalNow())), 177 | DataInicio = Date.StartOfYear(MenorData), 178 | DataFim = Date.EndOfYear(MaiorData), 179 | Dias = Duration.Days(DataFim- DataInicio) +1, 180 | ListarDatas = List.Dates(DataInicio, Dias, #duration(1,0,0,0)), 181 | Tabela = #table( 182 | type table[ 183 | Data = date, 184 | Dia = Int64.Type, 185 | Ano = Int64.Type, 186 | NomeMes = text, 187 | MesAbre = text, 188 | MesAno = text, 189 | MesNum = number, 190 | AnoMesINT = number, 191 | Trimestre = Int64.Type, 192 | TrimestreAbreviado = text, 193 | Bimestre = text, 194 | Semestre = text, 195 | Semana = Int64.Type, 196 | DiaSemana = Int64.Type, 197 | NomeDia = text, 198 | DiaAtualTF = Logical.Type, 199 | EMesAtualTF = Logical.Type, 200 | EAnoAtualTF = Logical.Type, 201 | MesAtual = text, 202 | AnoAtual = text 203 | 204 | 205 | ], 206 | List.Transform( 207 | ListarDatas, 208 | each { 209 | _, 210 | Date.Day(_), 211 | Date.Year(_), 212 | Text.Proper( Date.MonthName(_)), 213 | Text.Proper(Text.Start(Date.MonthName(_), 3)), 214 | Text.Proper(Text.Start(Date.MonthName(_), 3)) & "-" & Text.End(Text.From(Date.Year(_)), 2), 215 | Date.Month(_), 216 | Date.Year(_) * 100 + Date.Month(_), 217 | Date.QuarterOfYear(_), 218 | Text.From(Date.QuarterOfYear(_)) & "º Trim ", 219 | Text.From( Number.RoundUp( Date.Month(_)/2,0)) & "º Bim", 220 | Text.From( Number.RoundUp( Date.Month(_)/6,0)) & "º Sem", 221 | Date.WeekOfMonth(_), 222 | Date.DayOfWeek(_), 223 | Date.DayOfWeekName(_), 224 | Date.IsInCurrentDay(_), 225 | Date.IsInCurrentMonth(_), 226 | Date.IsInCurrentYear(_), 227 | if Date.IsInCurrentMonth(_) and Date.IsInCurrentYear(_) then "Mês Atual" else Text.Proper(Text.Start(Date.MonthName(_), 3)), 228 | if Date.IsInCurrentYear(_) then "Ano Atual" else Text.From(Date.Year(_)) 229 | 230 | 231 | } 232 | 233 | ) 234 | ) 235 | in 236 | Tabela 237 | ``` 238 | 239 | annotation PBI_NavigationStepName = Navegação 240 | 241 | annotation PBI_ResultType = Table 242 | --------------------------------------------------------------------------------