DAX Intermediário no Power BI
Carl Rosseel
Curriculum Manager
Funções lógicas agem sobre uma expressão e retornam informações sobre os valores ou conjuntos na expressão.
As mais usadas são:
IF()AND(), OR(), NOT()SWITCH()Estrutura:
IF(<logical_test>, <value_if_true>, <value_if_false>)Exemplo:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached")Estrutura:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Exemplo:
Performance = IF([Total Sales] >= 50 000, "Target Reached", "Target Not Reached") | Name | Total Sales |
|---|---|
| Jenny | 48,431 |
| Jane | 76,528 |
| Dwayne | 24,167 |
| Thomas | 52,125 |
Estrutura:
IF(<logical_test>, <value_if_true>[, <value_if_false>])Exemplo:
Performance = IF([Total_Sales] >= 50 000, "Target Reached", "Target Not Reached")| Name | Total Sales | Performance |
|---|---|---|
| Jenny | 48,431 | Target not Reached |
| Jane | 76,528 | Target Reached |
| Dwayne | 24,167 | Target Not Reached |
| Thomas | 52,125 | Target Reached |
Os três operadores retornam TRUE ou FALSE.
AND(<logical1>,<logical2>)TRUE se as duas condições forem TRUEAND(5 < 4, 5 < 6) = AND(FALSE, TRUE) = FALSEOR(<logical1>,<logical2>)TRUE se pelo menos uma condição for TRUEOR(5 < 4, 5 < 6) = OR(FALSE, TRUE) = TRUENOT(<logical>)TRUE para FALSE e vice-versaNOT(OR(5 < 4, 5 < 6)) = NOT(TRUE) = FALSEAND pode ser substituído por &&
AND(5 < 4, 5 < 6) = 5 < 4 && 5 < 6 OR pode ser substituído por ||
OR(5 < 4, 5 < 6) = 5 < 4 || 5 < 6Avalia uma expressão contra uma lista de valores e retorna um entre vários resultados possíveis.
SWITCH(<expression>, <value>, <result>[, <value>, <result>] ... [, <else>])IF() aninhadosPerformance = SWITCH(TRUE,
[Total_Sales] < 25 000, "Poor",
[Total_Sales] < 50 000, "Below expectations",
[Total_Sales] < 75 000, "Above expectations",
"Exceptional")
Performance = SWITCH(TRUE,
[Total_Sales] < 25 000, "Poor",
[Total_Sales] < 50 000, "Below expectations",
[Total_Sales] < 75 000, "Above expectations",
"Exceptional")
| Name | Total Sales |
|---|---|
| Jenny | 48,431 |
| Jane | 76,528 |
| Dwayne | 24,167 |
| Thomas | 52,125 |
Performance = SWITCH(TRUE,
[Total_Sales] < 25 000, "Poor",
[Total_Sales] < 50 000, "Below expectations",
[Total_Sales] < 75 000, "Above expectations",
"Exceptional")
| Name | Total Sales | Performance |
|---|---|---|
| Jenny | 48,431 | Below Expectations |
| Jane | 76,528 | Exceptional |
| Dwayne | 24,167 | Poor |
| Thomas | 52,125 | Above expectations |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Clothing Type |
|---|
| Shoes |
| Pants |
| Belt |
| T-shirt |
DISCOUNT = SWITCH([Clothing Type],
"Shoes", 0.15,
"Pants", 0.20,
"Belts", 0.30,
"T-shirt", 0.25)
| Clothing Type | Discount |
|---|---|
| Shoes | 15% |
| Pants | 20% |
| Belt | 30% |
| T-shirt | 25% |
DAX Intermediário no Power BI