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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
GovindPrajapat
Frequent Visitor

Power M Query

I want to add a custom column in my power bi dataset whare i want if the coloumn "A" is true the value should be 0 else the value should be the difference of previous records "Datetime" coloumn value and the current records "Datetime" Coluumn value. how can i do it in power bi using M Language Query.

1 ACCEPTED SOLUTION
baghdadi62
Resolver III
Resolver III

Hi,
First, add an index column to the table starting from zero.

Next, write a formula like the following to check the value of column A and, if it evaluates to true, subtract the date value of the current row from the date value of the previous row:
Please note that columns in Power Query are the list type, and you can access their values through the item number or index number by using curly braces {} at the end of their names.

Imagine that we have a column named A and whant to acces to the 5nth row of that column, the code is: [a]{5}

 

1.JPG

View solution in original post

7 REPLIES 7
lherna55
Frequent Visitor

Hi¡¡

I'm trying to resolve the same kind of problem.

 

I have this formula :

lherna55_0-1708296337933.png

but in the end the column gives me an error, I changes the date to text, but it gives me an error anyway.

 

Can you help me please. @AlienSx  and @baghdadi62

 

 

GovindPrajapat
Frequent Visitor

Thankyou so much @AlienSx  and @baghdadi62,  it worked.

baghdadi62
Resolver III
Resolver III

A lovely solution proposed by @AlienSx 🌷

I tested it. In a larger file, it performed better.  💪 🙏

 

Before:
1.JPG

 

After:

2.JPG

baghdadi62
Resolver III
Resolver III
baghdadi62
Resolver III
Resolver III

Hi,
First, add an index column to the table starting from zero.

Next, write a formula like the following to check the value of column A and, if it evaluates to true, subtract the date value of the current row from the date value of the previous row:
Please note that columns in Power Query are the list type, and you can access their values through the item number or index number by using curly braces {} at the end of their names.

Imagine that we have a column named A and whant to acces to the 5nth row of that column, the code is: [a]{5}

 

1.JPG

Hi @baghdadi62 ,

 

I tried it and it worked for me. I have successfully achived what i was looking for. But After applying queries the data started to load and from last 7 hours it is being load. It is not coming out of this process. I have 100000 records in my data. The load has reached 16 GB and still Going on. Kindly suggest a way to resolve this issue.

@BA_Pete @slorin @AlienSx @ronrsnfld @collinsg Please help if you know the reason behind this situation and the solution for the same

 

GovindPrajapat_0-1689658817823.png

 

 

 

Hi, @GovindPrajapat lets try smth simple first. You need to add new step

whatever = List.Buffer(#"Added Index"[oDate])

and replace #"Added Index"[oDate] phrase in your Table.AddColumn step with "whatever". 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors