Formelspråket som används i Power BI heter DAX - Data Analysis Expressions. Språket utgörs av ett stort antal funktioner med konstanter och operatorer vilka används i formler och uttryck för att beräkna ett eller flera värden. DAX skapar helt enkelt ny information utifrån data som redan finns i din datamodell.
Funktionerna i DAX delar vi in i följande grupper: DATETIME, FILTER, INFO, LOGICAL, MATHTRIG, PARENTCHILD, STATISTICAL, TEXT, TIMEINTELLIGENCE samt OTHER.
DAX Function: DIVIDE
Reference group: MATHTRIG
Att försöka genomföra en division där nämnaren är 0 eller saknar värde låter sig inte göras och ställer till med problem bl a för påföljande beräkningar. Resultatet av en sådan division brukar generera någon form av felmeddelande och eventuella påföljande beräkningar som är beroende av resultatet av divisionen blir också fel. För att undvika detta använder du inte en vanlig matematisk division med täljare, nämnare och en kvot som resultat utan du använder DIVIDE-funktionen.
Givetvis kan man genomföra en normal matematisk division med vanligt bråktecken (/) men om nämnaren är 0 eller saknar värde blir resultatet ingen kvot utan felmeddelandet ”Infinity”.
DIVIDE function (DAX)
DIVIDE-funktionen genomför divisionen men om nämnaren är 0 eller saknar värde presenteras ett förutbestämt värde i stället för felmeddelandet.
Syntax: DIVIDE(<numerator>; <denominator> [; <alternateresult>])
Exempel 1.
I exemplet genomför vi en helt vanlig division med bråktecken. Kvoten presenteras som ”Infinity” när nämnaren är 0 eller utan värde. Eventuella beräkningar som inkluderar kvoten blir fel.
För att beräkna ”Division” använder vi följande syntax:
Division = Täljare/Nämnare
Exempel 2.
I exemplet genomför vi en division med DIVIDE-funktionen. Kvoten får det fördefinierade värdet är 0 då division inte är genomförbar. Eventuella beräkningar som inkluderar kvoten kan genomföras.
För att beräkna ”Divide 0” använder vi följande syntax:
Divide 0 = DIVIDE(Täljare;Nämnare;0)
Exempel 3.
I exemplet genomför vi en division med DIVIDE-funktionen. Kvoten får det fördefinierade värdet blank/tom då division inte är genomförbar. Eventuella beräkningar som inkluderar kvoten kan genomföras.
För att beräkna ”Divide Blank” använder vi följande syntax:
Divide Blank = DIVIDE(Täljare;Nämnare;Blank())
Flera MATHTRIG funktioner (DAX)
Ovan har du fått exempel på hur du, genom att använda DIVIDE-funktionen, kan undvika felmeddelande och följdfel då division inte är genomförbar. Det finns ytterligare 44 MATHTRIG-funktioner i Power BI.
Vill du veta mer vilka MATHTRIG-funktioner som finns i Power BI kan du ladda ner vår Power BI applikation som visar alla MATHTRIG-funktioner. För att kunna använda Power BI applikationen behöver du ha Power BI Desktop installerad på din dator. Power BI Desktop är gratis och kan laddas ner här, https://powerbi.microsoft.com/sv-se/desktop/.
Vi kan naturligtvis hjälpa till med installation och att komma igång med PBI.
Håll utkik efter ytterligare blogginlägg .
För att kunna använda Power BI applikationen behöver du ha Power BI Desktop installerad på din dator. Power BI Desktop är gratis och kan laddas ner här, https://powerbi.microsoft.com/sv-se/desktop/.
Om du inte redan har Power BI Desktop installerat och behöver hjälp med detta kan vi naturligtvis hjälpa till.
Håll utkik efter ytterligare blogginlägg på denna site.