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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

translate pseudocode in power query code

I wrote some lines of pseudocode that i  wuold like to translate in power query code.

This code would help me to create a new column in CAR_ MILEAGE table with the name of the employee or the organizational site that had the car in a certain period.

 

UPPER CASE NAME=TABLES

.lower case name= atttributes

TABLE[i]= row in position i of table TABLE

.fromDate.month= month of the attribute fromDate that is in Date format.

CAR_MILEAGE has already a column called month that contains the number of the month

 

 

var found=false

for each row(i) in CAR_MILEAGE <-(looping)
    table.selectrows(table as CAR_ASSIGNMENT,condition as CAR_ASSIGNMENT.car==CAR_MILEAGE[i].car) as TAB1 //get all the row that satisfy the condition in a list/table
        found=false;
        for each row(j) in TAB1 <-(looping)
            if(CAR_MILEAGE[i].month>= TAB1[j].fromeDate.month && CAR_MILEAGE[i].year>= TAB1[j].fromDate.year) 
                && (TAB1[j].toDate=="" or (CAR_MILEAGE[i].month<= TAB1[j].toDate.month && CAR_MILEAGE[i].year<= TAB1[j].toDate.year)) 
                then found=true
                    if TAB1[j].businessSite=="" return TAB1[j].employee
                    else return TAB1[j].businessSite
                    
            else continue

        if(found==false)
            return "err"
        else continue

 

 

 

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Can you please post sample data also? - How to provide sample data

 

👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)

How to get your questions answered quickly -- How to provide sample data

Anonymous
Not applicable

this is car mileage: andlor_0-1660891778474.png

this is car assignment:

andlor_1-1660892118768.png

NOTE: in car assignment the fromDate start always at the start of a month and ends at the end of a month or is still going if the value is emprty.

 

I want to retrieve the business site (LA, NY etcc..) or the employee(joe,...) which was using the company car

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors