DAX Nedir? Power BI İçin En Önemli DAX Formülleri

Power BI'da ölçüler, hesaplanan sütunlar, filtre bağlamı ve zaman bazlı analizler için en önemli DAX fonksiyonlarını gerçek örneklerle inceliyorum.

  • Araçlar
  • Veri Görselleştirme

Power BI ile dashboard hazırlarken grafiklerin arkasında çalışan hesaplama dili çoğu zaman DAX'tır. DAX, yani Data Analysis Expressions, verileri filtre bağlamına göre analiz etmek, ölçüler oluşturmak ve daha gelişmiş hesaplamalar yapmak için kullanılan ifade dilidir.

DAX öğrenmeye başlarken yüzlerce fonksiyonu ezberlemek yerine, measure ile calculated column arasındaki farkı ve SUM, CALCULATE, FILTER, SUMX, DISTINCTCOUNT gibi temel yapıların mantığını anlamak çok daha değerli.

“DAX'ın gücü sadece matematiksel işlem yapmakta değil, sonucu bulunduğu filtre bağlamına göre yeniden hesaplayabilmesinde.”

DAX Nedir?

DAX, Power BI başta olmak üzere Microsoft'un analitik araçlarında kullanılan bir formül dilidir. Basit toplamların yanında filtrelenmiş toplamlar, müşteri sayıları, büyüme oranları, dönem karşılaştırmaları ve daha gelişmiş iş metrikleri oluşturmak için kullanılır.

DAX'ın temel mantığı
  1. Veri
    Modeli
  2. Measure
  3. Filtre
    Bağlamı
  4. Hesaplama
  5. KPI

Measure ve Calculated Column Arasındaki Fark

DAX öğrenirken ilk anlaşılması gereken konulardan biri measure ile calculated column arasındaki fark. İkisi de DAX kullanır; ancak çalışma biçimleri ve kullanım amaçları farklıdır.

ÖzellikMeasureCalculated column
Hesaplama zamanıGörsel sorgulandığındaVeri yenilenirken
SonuçFiltre bağlamına göre değişebilirHer satır için değer üretir
KullanımKPI, toplam, oran, trendYeni kategori / satır bazlı alan
ÖrnekToplam satışSatış seviyesi
Pratik yaklaşım: Bir değeri rapordaki filtrelere göre dinamik olarak hesaplamak istiyorsanız çoğu durumda measure düşünün. Her satıra sabit bir mantık uygulamak istiyorsanız calculated column daha uygun olabilir.

1. SUM — Toplam Hesaplamak

DAX öğrenmeye başlanabilecek en temel fonksiyonlardan biri SUM. Örneğin toplam satış için:

Temel toplam measure'ı
Toplam Satis =
SUM(Satis[NetSatis])

Bu measure bir karta, tabloya veya grafiğe eklendiğinde bulunduğu filtre bağlamına göre toplam satışı hesaplar.

2. DISTINCTCOUNT — Benzersiz Değerleri Saymak

Toplam kayıt sayısı ile benzersiz müşteri sayısı aynı şey değildir. Benzersiz müşterileri hesaplamak için DISTINCTCOUNT kullanılabilir.

Benzersiz müşteri sayısı
Musteri Sayisi =
DISTINCTCOUNT(Satis[MusteriID])

Bu measure ile “Kaç farklı müşterimiz var?” sorusuna cevap verebiliriz.

3. CALCULATE — DAX'ın En Önemli Fonksiyonlarından Biri

CALCULATE, mevcut filtre bağlamını değiştirerek bir ifadenin yeniden değerlendirilmesini sağlar. DAX'ın en güçlü ve en sık kullanılan yapı taşlarından biri olmasının temel nedeni bu.

Belirli bir kategori için satış
Elektronik Satis =
CALCULATE(
    [Toplam Satis],
    Urun[Kategori] = "Elektronik"
)

Burada önce daha önce oluşturduğumuz [Toplam Satis] measure'ını alıyoruz, ardından hesaplama bağlamını “Elektronik” kategorisiyle değiştiriyoruz.

Filtre

Bağlamı değiştirir

Bir ölçüyü farklı filtre koşullarında yeniden hesaplamayı sağlar.

Analiz

Karşılaştırma kurar

Toplam, kategori, dönem veya segment bazlı analizleri kolaylaştırır.

4. FILTER — Daha Kontrollü Filtreler

FILTER, özellikle karmaşık koşullar söz konusu olduğunda satır bazında bir filtre tablosu oluşturmak için kullanılır.

Koşullu toplam
Yuksek Satis =
CALCULATE(
    [Toplam Satis],
    FILTER(
        Satis,
        Satis[NetSatis] > 10000
    )
)

Burada 10.000'in üzerindeki satış kayıtlarını filtreleyerek toplamı hesaplıyoruz.

Not: FILTER güçlüdür; ancak her durumda gerekli değildir. Basit filtreler için CALCULATE içinde doğrudan kolon koşulları daha sade bir yaklaşım olabilir.

5. SUMX — Satır Satır Hesaplama

SUM doğrudan bir sütunu toplarken, SUMX bir tablo üzerinde satır satır bir ifade hesaplayıp sonuçları toplar.

Adet × birim fiyat = ciro
Toplam Ciro =
SUMX(
    Satis,
    Satis[Adet] * Satis[BirimFiyat]
)

Örneğin veri setinde hazır bir “NetSatış” sütunu bulunmuyorsa, adet ile birim fiyatı her satır için çarpıp toplamını alabiliriz.

6. CASE WHEN'in DAX Karşılığı: IF ve SWITCH

DAX'ta SQL'deki CASE WHEN mantığı için çoğunlukla IF, daha fazla seçenek olduğunda ise SWITCH kullanılır.

IF ve SWITCH örnekleri
Satis Seviyesi =
IF(
    [Toplam Satis] >= 100000,
    "Yüksek",
    "Normal"
)

-- Birden fazla seçenek için
Satis Seviyesi =
SWITCH(
    TRUE(),
    [Toplam Satis] >= 100000, "Yüksek",
    [Toplam Satis] >= 50000, "Orta",
    "Düşük"
)

7. Zaman Bazlı Hesaplamalar

Power BI dashboard'larında en sık ihtiyaç duyulan analizlerden biri dönem karşılaştırması. Bunun için tarih tablosunun düzgün kurulması ve DAX'ın zaman fonksiyonlarının doğru kullanılması önemli.

Yıl içinden bugüne: DATESYTD

YTD satış
YTD Satis =
CALCULATE(
    [Toplam Satis],
    DATESYTD(Takvim[Tarih])
)

Önceki yıl: SAMEPERIODLASTYEAR

Geçen yılın aynı dönemi
Gecen Yil Satis =
CALCULATE(
    [Toplam Satis],
    SAMEPERIODLASTYEAR(Takvim[Tarih])
)

Yıllık değişim oranı

Yıllık büyüme
Yillik Buyume =
DIVIDE(
    [Toplam Satis] - [Gecen Yil Satis],
    [Gecen Yil Satis]
)

Bu üç measure birlikte kullanıldığında satışların hem mevcut dönemdeki seviyesini hem de önceki yıla göre değişimini dashboard üzerinde gösterebiliriz.

8. DIVIDE — Oranları Daha Güvenli Hesaplamak

DAX'ta oran hesaplamak için DIVIDE kullanmak, doğrudan bölme işlemine göre daha kontrollü bir yaklaşım.

Dönüşüm oranı
Donusum Orani =
DIVIDE(
    [Siparis Sayisi],
    [Ziyaret Sayisi]
)

DIVIDE paydanın sıfır olduğu durumları yönetmek için kullanılabilir ve isteğe bağlı olarak alternatif bir sonuç değeri de alabilir.

9. Filtre Bağlamını Anlamak

DAX öğrenirken en kritik kavramlardan biri filtre bağlamı (filter context). Aynı measure bir kartta toplamı gösterirken, bir grafik üzerinde kategori veya tarih filtresine göre farklı sonuçlar üretebilir.

Aynı measure, farklı bağlamlar
  1. Toplam
    Satış
  2. Yıl =
    2025
  3. Kategori =
    Elektronik
  4. Bölge =
    İstanbul

Bu yüzden DAX'ı yalnızca “formül dili” olarak değil, filtre bağlamında hesaplama dili olarak düşünmek çok daha faydalı.

10. İyi Bir DAX Measure Nasıl Yazılır?

İsimlendirme

Anlamlı isimler

[Toplam Satis] gibi ne yaptığı açık isimler kullan.

Tekrar

Yeniden kullan

Aynı hesabı farklı measure'larda tekrar etmek yerine temel bir measure oluştur.

Sadelik

Basit başla

Önce temel measure'ı oluştur, ihtiyaç oldukça genişlet.

Bağlam

Filtreyi düşün

Measure'ın farklı görsellerde hangi bağlamda çalışacağını kontrol et.

Performans

Maliyeti izle

Gereksiz karmaşık hesaplamalardan kaçın.

Doğrulama

Sonucu kontrol et

DAX sonucunu bağımsız bir hesapla veya kaynak veriyle karşılaştır.

En Çok Kullanılan DAX Fonksiyonları

FonksiyonTemel kullanımÖrnek ihtiyaç
SUM()ToplamaToplam satış
CALCULATE()Filtre bağlamını değiştirmeKategori / dönem bazlı ölçü
FILTER()Tabloyu koşula göre filtrelemeKarmaşık filtreler
SUMX()Satır bazlı ifade + toplamaAdet × fiyat
DISTINCTCOUNT()Benzersiz sayımMüşteri sayısı
DIVIDE()BölmeOran ve yüzde
DATESYTD()YTD hesaplamaYıl içi satış
SAMEPERIODLASTYEAR()Önceki yıl dönemiYıllık karşılaştırma
IF() / SWITCH()Koşullu mantıkSegment / sınıflandırma

Mini Bir DAX Analiz Seti

Aşağıdaki measure'lar, basit bir satış dashboard'ı için iyi bir başlangıç oluşturur:

Temel KPI seti
Toplam Satis =
SUM(Satis[NetSatis])

Musteri Sayisi =
DISTINCTCOUNT(Satis[MusteriID])

YTD Satis =
CALCULATE(
    [Toplam Satis],
    DATESYTD(Takvim[Tarih])
)

Gecen Yil Satis =
CALCULATE(
    [Toplam Satis],
    SAMEPERIODLASTYEAR(Takvim[Tarih])
)

Yillik Buyume =
DIVIDE(
    [Toplam Satis] - [Gecen Yil Satis],
    [Gecen Yil Satis]
)

Bu birkaç measure ile bile toplam satış, müşteri sayısı, YTD performansı ve yıllık büyüme gibi temel KPI'lar oluşturulabilir.

Sonuç

DAX, Power BI'da yalnızca birkaç toplama formülünden ibaret değil. Özellikle measure mantığını, filtre bağlamını ve CALCULATE gibi temel fonksiyonların nasıl çalıştığını anlamaya başladığınızda çok daha gelişmiş analizler oluşturabilirsiniz.

Başlangıç için SUM, DISTINCTCOUNT, CALCULATE, FILTER, SUMX, DIVIDE ve zaman bazlı fonksiyonları öğrenmek güçlü bir temel sağlar. Sonrasında daha gelişmiş DAX fonksiyonlarına geçmek çok daha kolay hale gelir.

“İyi bir DAX formülü sadece doğru sonucu üretmez; farklı filtrelerde de neden o sonucu verdiğini anlayabileceğiniz kadar açık bir mantığa sahiptir.”

When you build a dashboard in Power BI, the calculation language running behind the visuals is usually DAX. DAX, short for Data Analysis Expressions, is the expression language used to analyse data according to filter context, create measures and build more advanced calculations.

Rather than memorising hundreds of functions, it is far more valuable to understand the difference between a measure and a calculated column and the logic of core structures such as SUM, CALCULATE, FILTER, SUMX and DISTINCTCOUNT.

“The power of DAX is not only in doing arithmetic, but in being able to recalculate the result according to the filter context it sits in.”

What Is DAX?

DAX is a formula language used in Microsoft's analytics tools, Power BI first among them. Beyond simple totals, it is used to build filtered totals, customer counts, growth rates, period comparisons and more advanced business metrics.

The basic logic of DAX
  1. Data
    Model
  2. Measure
  3. Filter
    Context
  4. Calculation
  5. KPI

Measure vs Calculated Column

One of the first things to understand in DAX is the difference between a measure and a calculated column. Both use DAX, but they work differently and serve different purposes.

PropertyMeasureCalculated column
When it is calculatedWhen the visual is queriedWhen the data is refreshed
ResultCan change with the filter contextProduces a value for every row
UsageKPI, total, ratio, trendNew category / row-level field
ExampleTotal salesSales level
A practical rule: If you want a value calculated dynamically according to the report filters, a measure is usually the answer. If you want to apply fixed logic to every row, a calculated column may fit better.

1. SUM — Calculating a Total

SUM is one of the most basic functions to start with. For total sales, for example:

A basic total measure
Total Sales =
SUM(Sales[NetSales])

When this measure is added to a card, a table or a chart, it calculates total sales according to the filter context it is in.

2. DISTINCTCOUNT — Counting Unique Values

The total number of records and the number of unique customers are not the same thing. DISTINCTCOUNT can be used to count unique customers.

Unique customer count
Customer Count =
DISTINCTCOUNT(Sales[CustomerID])

With this measure we can answer “How many different customers do we have?”.

3. CALCULATE — One of the Most Important DAX Functions

CALCULATE re-evaluates an expression by changing the current filter context. That is the main reason it is one of the most powerful and most frequently used building blocks in DAX.

Sales for a specific category
Electronics Sales =
CALCULATE(
    [Total Sales],
    Product[Category] = "Electronics"
)

Here we take the [Total Sales] measure created earlier and then change the calculation context with the “Electronics” category.

Filter

Changes the context

Lets you recalculate a measure under different filter conditions.

Analysis

Builds comparisons

Makes total, category, period or segment based analyses easier.

4. FILTER — More Controlled Filters

FILTER is used to build a row-level filter table, especially when the conditions get complex.

A conditional total
High Sales =
CALCULATE(
    [Total Sales],
    FILTER(
        Sales,
        Sales[NetSales] > 10000
    )
)

Here we filter the sales records above 10,000 and calculate the total from them.

Note: FILTER is powerful, but it is not always needed. For simple filters, column conditions written directly inside CALCULATE can be the cleaner approach.

5. SUMX — Row-by-Row Calculation

While SUM adds up a column directly, SUMX evaluates an expression row by row over a table and then sums the results.

Quantity × unit price = revenue
Total Revenue =
SUMX(
    Sales,
    Sales[Quantity] * Sales[UnitPrice]
)

If the data set has no ready-made “net sales” column, for example, we can multiply quantity by unit price for each row and take the total.

6. The DAX Equivalent of CASE WHEN: IF and SWITCH

For the CASE WHEN logic of SQL, DAX mostly uses IF, or SWITCH when there are more options.

IF and SWITCH examples
Sales Level =
IF(
    [Total Sales] >= 100000,
    "High",
    "Normal"
)

-- For more than one option
Sales Level =
SWITCH(
    TRUE(),
    [Total Sales] >= 100000, "High",
    [Total Sales] >= 50000, "Medium",
    "Low"
)

7. Time-Based Calculations

Period comparison is one of the most requested analyses in Power BI dashboards. It needs a properly built date table and the correct use of DAX time intelligence functions.

Year to date: DATESYTD

YTD sales
YTD Sales =
CALCULATE(
    [Total Sales],
    DATESYTD(Calendar[Date])
)

Previous year: SAMEPERIODLASTYEAR

The same period last year
Last Year Sales =
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR(Calendar[Date])
)

Year-over-year change

Annual growth
Annual Growth =
DIVIDE(
    [Total Sales] - [Last Year Sales],
    [Last Year Sales]
)

Used together, these three measures show both the current level of sales and the change against the previous year on a dashboard.

8. DIVIDE — Calculating Ratios More Safely

Using DIVIDE for ratios in DAX is a more controlled approach than a direct division.

Conversion rate
Conversion Rate =
DIVIDE(
    [Order Count],
    [Visit Count]
)

DIVIDE can handle the cases where the denominator is zero, and it optionally takes an alternative result value.

9. Understanding Filter Context

One of the most critical concepts in DAX is filter context. The same measure can show a grand total on a card and produce different results on a chart according to the category or date filter.

The same measure, different contexts
  1. Total
    Sales
  2. Year =
    2025
  3. Category =
    Electronics
  4. Region =
    Istanbul

That is why it helps to think of DAX not only as a “formula language” but as a language that calculates within a filter context.

10. How to Write a Good DAX Measure

Naming

Meaningful names

Use names such as [Total Sales] that make the purpose obvious.

Reuse

Build on base measures

Instead of repeating the same calculation, create one base measure and reuse it.

Simplicity

Start simple

Create the base measure first and extend it as the need appears.

Context

Think about filters

Check which context the measure will run in across different visuals.

Performance

Watch the cost

Avoid unnecessarily complex calculations.

Validation

Check the result

Compare the DAX output with an independent calculation or the source data.

The Most Used DAX Functions

FunctionMain useExample need
SUM()SummingTotal sales
CALCULATE()Changing the filter contextCategory / period based measure
FILTER()Filtering a table by a conditionComplex filters
SUMX()Row-level expression + sumQuantity × price
DISTINCTCOUNT()Unique countCustomer count
DIVIDE()DivisionRatios and percentages
DATESYTD()YTD calculationSales within the year
SAMEPERIODLASTYEAR()The same period last yearYear-over-year comparison
IF() / SWITCH()Conditional logicSegmentation / classification

A Mini DAX Analysis Set

The measures below make a good starting point for a simple sales dashboard:

A base KPI set
Total Sales =
SUM(Sales[NetSales])

Customer Count =
DISTINCTCOUNT(Sales[CustomerID])

YTD Sales =
CALCULATE(
    [Total Sales],
    DATESYTD(Calendar[Date])
)

Last Year Sales =
CALCULATE(
    [Total Sales],
    SAMEPERIODLASTYEAR(Calendar[Date])
)

Annual Growth =
DIVIDE(
    [Total Sales] - [Last Year Sales],
    [Last Year Sales]
)

Even these few measures are enough to build core KPIs such as total sales, customer count, YTD performance and annual growth.

Conclusion

DAX in Power BI is much more than a handful of summing formulas. Once you start to understand the logic of measures, filter context and how core functions such as CALCULATE work, you can build far more advanced analyses.

Learning SUM, DISTINCTCOUNT, CALCULATE, FILTER, SUMX, DIVIDE and the time intelligence functions gives a strong foundation to start from. Moving on to more advanced DAX functions becomes much easier afterwards.

“A good DAX formula does not only produce the right result; its logic is clear enough that you can see why it gives that result under different filters.”

Python ile Veri Temizleme: Pratik İpuçları

Power BI Dashboard Tasarlarken Dikkat Edilmesi Gerekenler

Veri Analistinin Bir Günlük Çalışma Akışı

Python ile veri görselleştirme yöntemleri

Python ile veri görselleştirme yöntemleri

Big Data (Büyük Veri) Nedir?