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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.