Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

DAX to SQL code help

HI Experts,

Could anyone please translate below DAX into SQL please

 

1. AIMS = IF(LEN(A.L)>=10 and IFERROR(VALUE(RIGHT(Asset[A_L],1)),FALSE()),"AIMS","ANIMS")

2. AIMS = IF(Asset[AGAL] IN DISTINCT('H S'[AG]) && A[AIMS]="AIMS","I M S","N i M S")

3. AGAL = A[A_L] & "_" & A[AG]

4. AIMLS = IF(Asset[AGAL IN DISTINCT('H S'[AG]) && Asset[AIMxS]="AIMXS","I M S","N in M S")

 

thanks 

1 ACCEPTED SOLUTION
technolog
Super User
Super User

Hi!

The DAX expressions you provided can be translated into SQL as follows:

For the DAX expression:
AIMS = IF(LEN(A.L)>=10 and IFERROR(VALUE(RIGHT(Asset[A_L],1)),FALSE()),"AIMS","ANIMS")
The SQL translation would be:

CASE
WHEN LEN(A.L) >= 10 AND ISNUMERIC(RIGHT(Asset.A_L, 1)) = 1 THEN 'AIMS'
ELSE 'ANIMS'
END AS AIMS
For the DAX expression:
AIMS = IF(Asset[AGAL] IN DISTINCT('H S'[AG]) && A[AIMS]="AIMS","I M S","N i M S")
The SQL translation would be:

CASE
WHEN Asset.AGAL IN (SELECT DISTINCT AG FROM H_S) AND A.AIMS = 'AIMS' THEN 'I M S'
ELSE 'N i M S'
END AS AIMS
For the DAX expression:
AGAL = A[A_L] & "_" & A[AG]
The SQL translation would be:

CONCAT(A.A_L, '_', A.AG) AS AGAL
For the DAX expression:
AIMLS = IF(Asset[AGAL IN DISTINCT('H S'[AG]) && Asset[AIMxS]="AIMXS","I M S","N in M S")
The SQL translation would be:

CASE
WHEN Asset.AGAL IN (SELECT DISTINCT AG FROM H_S) AND Asset.AIMxS = 'AIMXS' THEN 'I M S'
ELSE 'N in M S'
END AS AIMLS

View solution in original post

1 REPLY 1
technolog
Super User
Super User

Hi!

The DAX expressions you provided can be translated into SQL as follows:

For the DAX expression:
AIMS = IF(LEN(A.L)>=10 and IFERROR(VALUE(RIGHT(Asset[A_L],1)),FALSE()),"AIMS","ANIMS")
The SQL translation would be:

CASE
WHEN LEN(A.L) >= 10 AND ISNUMERIC(RIGHT(Asset.A_L, 1)) = 1 THEN 'AIMS'
ELSE 'ANIMS'
END AS AIMS
For the DAX expression:
AIMS = IF(Asset[AGAL] IN DISTINCT('H S'[AG]) && A[AIMS]="AIMS","I M S","N i M S")
The SQL translation would be:

CASE
WHEN Asset.AGAL IN (SELECT DISTINCT AG FROM H_S) AND A.AIMS = 'AIMS' THEN 'I M S'
ELSE 'N i M S'
END AS AIMS
For the DAX expression:
AGAL = A[A_L] & "_" & A[AG]
The SQL translation would be:

CONCAT(A.A_L, '_', A.AG) AS AGAL
For the DAX expression:
AIMLS = IF(Asset[AGAL IN DISTINCT('H S'[AG]) && Asset[AIMxS]="AIMXS","I M S","N in M S")
The SQL translation would be:

CASE
WHEN Asset.AGAL IN (SELECT DISTINCT AG FROM H_S) AND Asset.AIMxS = 'AIMXS' THEN 'I M S'
ELSE 'N in M S'
END AS AIMLS

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors