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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

Power Query / M - If statement with Duration

Hi all,

 

I'm looking for a bit of help converting a column built with DAX into PowerQuery. 

 

Time for next period = if('Master Append'[EndTime] > 'Master Append'[Interval End] , datediff('Master Append'[Interval End],'Master Append'[EndTime],SECOND),0) 
 
Any help would be greatly appreciated! 
 
image.png
Kind regards,
 
Jordan 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

solved this, seems the brackets used were not allowing me to complete the M code.

 

Solution was = if [EndTime] > [Interval End] then Duration.Seconds([EndTime] - [Interval End]) else 0

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

I don't know the DAX sintax at all, but for what I can understand, would suggest to try this:

 

#"Time for next period" =List.Max({Duration.Seconds(#"Master Append"[Interval End]-#"Master Append"[EndTime]),0}

 

 

If you want, as seems from picture, add a new column with this data you shoul put the left right of the expression on the tool

add custom tool

 

 

 image.png

Anonymous
Not applicable

@Anonymous no luck unfortunately  

Anonymous
Not applicable

could you explain better what you mean by no lucky?
if you want useful help, you have to provide maximum information, otherwise it is difficult to imagine what happens

Anonymous
Not applicable

Hi @Anonymous ,

 

Your M below has not worked, but I believe it needs an if statement in there. I would expect something a bit more like "= if([EndTime] > [Interval End] then [Interval End]-[EndTime]else 0)" would be the answer I need? 

image.png

Kind regards,

 

Jordan 

Anonymous
Not applicable

Hi @Anonymous 

you didn't explained what error my code raises.

 

The logic of the expression I give is the same of your if ... then .. else. Only written in a differente way.

 

But now I have seen an error in the sintax

this

List.Max({Duration.Seconds(#"Master Append"[Interval End]-#"Master Append"[EndTime]),0}

 

should be

 

List.Max({Duration.Seconds(#"Master Append"[Interval End]-#"Master Append"[EndTime],0})

 

 

Anonymous
Not applicable

solved this, seems the brackets used were not allowing me to complete the M code.

 

Solution was = if [EndTime] > [Interval End] then Duration.Seconds([EndTime] - [Interval End]) else 0

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors