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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
enieuwer
Frequent Visitor

do while loop

Hi all,

 

I seem to be having trouble creating a variable value for a sort of do while loop. 

My formula works fine. But I need '[Object sort]-<number>' to work as a variable. How does this work?

Is this possible in DAX?

 

RESULT =
IF(
[Object A]=""
SWITCH(
TRUE(),
LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-1)<>"",LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-1),
LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-2)<>"",LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-2),
LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-3)<>"",LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-3),
LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-4)<>"",LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-4),
LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-5)<>"",LOOKUPVALUE(EQUIPMENTS[Object A],[Object sort],[Object sort]-5),
.........
),
BLANK()
)

3 REPLIES 3
Greg_Deckler
Super User
Super User

@enieuwer Here is how to do For and While loops in DAX: For and While Loops in DAX – Greg Deckler

And the videos:

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Hi Greg,

 

Thank you for you swift answer. 

Unfortunately your solution is above my knowledge of DAX. I was hoping for an easier solution.

 

Hi @enieuwer ,

In order to get a better understanding on your requirement and give you a suitable solution, could you please provide some raw data in your table 'EQUIPMENTS' (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. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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