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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors