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

SQL to DAX

Dear Community Members!



I have two SQL scripts and I would like to transform into DAX codes but it don't work for me either:



I have three different id: 0,1,2

1.

Full income costs:

=[fix basic costs] + If [extra costs]>=Sum(income costs) Where ([id]<>2;[id]) Then [extra costs]+Sum(income costs) Where ([id]=2;[id]) Else Sum([income costs])

My version:

Full income costs =

Actual[basic costs] + IF((Actual[extra costs] >= sum(Actual[income costs]) && Actual[id] <> 2); IF(Actual[id] = 2; (Actual[extra costs] + sum(Actual[income costs])); sum(Actual[income costs])); Actual[income costs])

2.

Full income costs with discounts:

=If Sum([income costs)])=0 or Sum([operational costs])=0 Then 0 Else [full income costs] - Sum([operational costs]) - [specific costs] - [discount cost]

My version:

Full income costs with discounts =

IF(sum(Actual[income costs]) = 0 || sum(Actual[operational costs]) = 0; 0; (Actual[income costs]-Actual[operational costs]-Actual[specific costs])-Actual[doscounts cost])

Thank you for you efforts,
5 REPLIES 5
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Can you share a sample? A dax formula has tight connections to the data model structure. Can you post the expected result? I'm afraid the first pseudo-code isn't clear. It could be like below.

measure 1 =
[fix basic costs]
    + IF (
        MIN ( actual[extra costs] ) >= SUM ( actual[income costs] )
            && MIN ( actual[id] ) <> 2;
        MIN ( actual[extra costs] ) + SUM ( actual[income costs] );
        IF (
            MIN ( actual[id] ) = 2;
            MIN ( actual[extra costs] ) + SUM ( actual[income costs] );
            SUM ( actual[income costs] )
        )
    )

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

result.jpg

Anonymous
Not applicable

Dear All,

 

I would like to correct and clarify the final result so I sent a new table which contain that column what I want to get with the two above SQL script.

 

Please help me to tranfer those SQL scripts into DAX codes.

 

 

Thank you for everyone.

 

Regards,

 

Attila

Anonymous
Not applicable

good result.jpg

 

 

 

Anonymous
Not applicable

Dear @v-jiascu-msft,

 

Firstly I really thank you your answer, secondly here is the sample which show my desired result.

I think the DAX code should work on Company_id level to count the proper number.

 

 Best regards,

 

Attila

 

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.