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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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:

 


@ 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!:
Mastering Power BI 2nd Edition

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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