ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Converting SQL Case When Statements to Power BI DAX

I have following case when statement in SQL which was joined multiple tables. How can i covert this

powerbi

dax

powerquery

Автор: vlogize

Загружено: 2025-05-28

Просмотров: 1

Описание: Learn how to transform SQL `case when` statements into Power BI DAX measures using simple steps and examples for effective data analysis.
---
This video is based on the question https://stackoverflow.com/q/65368091/ asked by the user 'user14854377' ( https://stackoverflow.com/u/14854377/ ) and on the answer https://stackoverflow.com/a/65370205/ provided by the user 'msta42a' ( https://stackoverflow.com/u/14366538/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.

Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: I have following case when statement in SQL which was joined multiple tables. How can i covert this into power bi DAX

Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.

If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Converting SQL CASE WHEN Statements to Power BI DAX: A Step-by-Step Guide

When working with SQL databases, the CASE WHEN statement is a powerful tool that allows you to perform conditional logic in your queries. However, as we transition from SQL to Power BI, we often face the challenge of converting these statements into DAX (Data Analysis Expressions) to apply similar logic in our reports. In this guide, we will tackle this conversion process, focusing on a practical example to illustrate the method.

Understanding the Problem

Let's consider the following SQL CASE WHEN statement, which evaluates a condition based on the statuses of the records in multiple tables:

[[See Video to Reveal this Text or Code Snippet]]

The above statement is checking the status of records in table A, combined with conditions from tables M and N. Our goal is to recreate this logic using DAX in Power BI.

Setting Up Your Data Model

Before we dive into DAX, it's essential to ensure that the relationships between your tables (A, M, and N) are correctly set up in Power BI. Here’s how to check this:

Open your Power BI model view.

Ensure that relationships between tables A, M, and N exist and are correctly defined. This means mapping the appropriate keys so that related data from these tables can be accessed seamlessly.

Once the relationships are confirmed, you can proceed to create a new measure to replicate the SQL logic.

Writing the DAX Measure

In DAX, we can use the SWITCH function combined with TRUE() to evaluate multiple conditions, similar to how CASE WHEN works in SQL. Here’s how to write your DAX measure:

[[See Video to Reveal this Text or Code Snippet]]

Breakdown of the DAX Measure

SWITCH(TRUE(), ...): This initiates conditional checks. TRUE() is used so that DAX evaluates each condition in sequence.

Conditions: Each line checks specific criteria similar to your SQL statement:

If A[Status] is "ACTIVATED" and M[Caller] is not blank, return "ACTIVE".

If A[Status] is "ACTIVATED", M[Caller] is blank, and N[Callingparty] is not blank, return "AINACTIVE".

If A[Status] is "ACTIVATED" and both M[Caller] and N[Callingparty] are blank, return "NO_USAGE".

Label for ELSE: This is optional and can be customized based on what you want to measure when all previous conditions fail.

Conclusion

transforming SQL CASE WHEN statements into Power BI DAX measures can be straightforward once you understand the underlying logic and the syntax differences. By correctly establishing relationships in your data model and using the SWITCH function effectively, you can replicate complex conditional evaluations in your Power BI reports.

Feel free to experiment with your conditions and make adjustments according to your specific data needs!

By mastering DAX, you will enhance your ability to analyze data effectively in Power BI, leading to better insights and decision-making.

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Converting SQL Case When Statements to Power BI DAX

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

An (Advanced) Introduction to DAX | Eugene Meidinger | SQL Trail Oct 2021

An (Advanced) Introduction to DAX | Eugene Meidinger | SQL Trail Oct 2021

Learn 12 Advanced SQL Concepts in 20 Minutes (project files included!)

Learn 12 Advanced SQL Concepts in 20 Minutes (project files included!)

Using the CASE statement in DAX and Power BI with SWITCH 🔔

Using the CASE statement in DAX and Power BI with SWITCH 🔔

Основы работы в Microsoft Power BI

Основы работы в Microsoft Power BI

10 Power BI UI/UX Tips to Instantly Improve Your Dashboards

10 Power BI UI/UX Tips to Instantly Improve Your Dashboards

Edit data in Power BI – Translytical task flows

Edit data in Power BI – Translytical task flows

Code along - build an ELT Pipeline in 1 Hour (dbt, Snowflake, Airflow)

Code along - build an ELT Pipeline in 1 Hour (dbt, Snowflake, Airflow)

LLM и GPT - как работают большие языковые модели? Визуальное введение в трансформеры

LLM и GPT - как работают большие языковые модели? Визуальное введение в трансформеры

Эти 5 СЕКРЕТНЫХ функций в Excel НИКТО не использует. Вот, что они делают!

Эти 5 СЕКРЕТНЫХ функций в Excel НИКТО не использует. Вот, что они делают!

Учебник по Power BI за 10 минут

Учебник по Power BI за 10 минут

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]