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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Masoud_
Frequent Visitor

How to write my excel formula in DAX

Hi every one,

 

I have a formula in Excel and I am trying to write it in DAX but I am new and I don't know how to do that.

The code is not complicated, but I am struggelling a few days to solve it.

=IF(OR((C5-C4)>0,(C4-C3)>0),1,IF(AND((C3-C2)>0,(C4-C5)>-0.05),1,0))

 

Does anyone knows how to do that?

 

Screenshot 2022-04-07 160410.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Masoud_ ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _cur = 'Table'[Celsius]
VAR _cur1 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 1 )
    )
VAR _cur2 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 2 )
    )
VAR _cur3 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 3 )
    )
VAR _cur4 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 4 )
    )
RETURN
    IF (
        _cur4 - _cur3 > 0
            || _cur3 - _cur2 > 0,
        1,
        IF ( _cur2 - _cur1 > 0 && _cur3 - _cur4 > -0.05, 1, 0 )
    )

yingyinr_0-1649757381042.png

If the above one can't help you get the desired result, please provide some sample data in the table (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @Masoud_ ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column = 
VAR _cur = 'Table'[Celsius]
VAR _cur1 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 1 )
    )
VAR _cur2 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 2 )
    )
VAR _cur3 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 3 )
    )
VAR _cur4 =
    CALCULATE (
        MAX ( 'Table'[Celsius] ),
        FILTER ( 'Table', 'Table'[Temp#55] = EARLIER ( 'Table'[Temp#55] ) + 4 )
    )
RETURN
    IF (
        _cur4 - _cur3 > 0
            || _cur3 - _cur2 > 0,
        1,
        IF ( _cur2 - _cur1 > 0 && _cur3 - _cur4 > -0.05, 1, 0 )
    )

yingyinr_0-1649757381042.png

If the above one can't help you get the desired result, please provide some sample data in the table (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

How to upload PBI in Community

Best Regards

@Anonymous 

Thank you for your answer. It worked perfectly.

I appreciate your time and effort.

Kind Regards,

Masoud

Ashish_Mathur
Super User
Super User

Hi,

While in cell G2, why should we refer to cells C5 and C4?  What is the logic? 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

So, it's a formula based on time period data and it needs 4 rows at a time to calculate a result.

Columns D, E and F are not concerned with this formula.

Hi,

Please state the rules very clearly and also show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

   The concept of formula is like this:

if (T(t)-T(t-1)>0) or (if T(t-1)-T(t-2) > 0
or T(t-2) - T (t-3) >0 and T (t-1) - T (t) > -0.05)

Result should be like this:

result1.png

 

lbendlin
Super User
Super User

Don't try to convert Excel concepts into Power BI. Instead, please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to assist you. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

TimeCelsius(°C)Humidity(%rh)Dew Point(°C)Formula1

12/11/2021 12:001874.513.40
12/11/2021 12:10187513.50
12/11/2021 12:20187513.50
12/11/2021 12:30187513.50
12/11/2021 12:40187513.50
12/11/2021 12:50187513.50
12/11/2021 13:00187513.50
12/11/2021 13:10187513.50
12/11/2021 13:201875.513.60

 

Data sample is like this table and formula is =IF(OR((C5-C4)>0,(C4-C3)>0),1,IF(AND((C3-C2)>0,(C4-C5)>-0.05),1,0)).

The result is 0 and 1.

result1.png

 

If I do not use power BI coding to calculate my formulas, how should I avoid generating too much-recorded data in the same worksheet? Also, my data are separated from case studies but need to process the same, and it takes a lot of space and human effort if I want to do all my analysis in Excel!

 

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.