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
Joop
New Member

if-then-else on comparing data from the previous field/record

Hi Community! I have an question on how to mimic an Excel if-then-else formula in Power BI. I don't want to use the function in the Excel base table, as I want to let PowerBI do all the work and calculations.

See here an example: I want to assign a certain value to the column "aantal", based in a comparison in the column "DatumTijdTee" of the current and the previous row value. Hope the picture explains better:

 

Knipsel.JPG

Is this a simple function, or do I have to create complicated DAX expressions?

 

Thanks for your help!

 

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

It can also be done in Power Query (M).

Code will be most efficient when you have the relevant current and previous values in 1 row.

This can be done by adding 2 index columns (1 starting with 0 and the other starting with 1) and then merge the table with itself.

An example in this video I created yesterday as an answer to a similar case.

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
Joop
New Member

<Hello Marcel,

 

thanks for the solution, especially the video. This helped me very much with my question!

 

Cheers, Joop

MarcelBeug
Community Champion
Community Champion

It can also be done in Power Query (M).

Code will be most efficient when you have the relevant current and previous values in 1 row.

This can be done by adding 2 index columns (1 starting with 0 and the other starting with 1) and then merge the table with itself.

An example in this video I created yesterday as an answer to a similar case.

Specializing in Power Query Formula Language (M)

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.