cancel
Showing results for
Did you mean:
Member

Hello, I´m using the following code:

#"Substract" = Table.AddColumn(MaxOfYear, "Diferencial aceite", each [MaxfYear] - [MinOfYear], type number)

To calculate the difference between the Max value and Min value from a column, but when the Min and Max is the same value I got 0 (obviusly), so I need to change the Min value to 0 so i get : MaxYfear - 0 = MaxfYear

How can I do this?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Change Code in AddColumn

you can use if/then/else for it.

#"Substract" = Table.AddColumn(MaxOfYear, "Diferencial aceite", each if [MaxfYear] = [MinOfYear] then [MaxfYear] else [MaxfYear] - [MinOfYear], type number)

Or do I understand you wrong and you expect something like: IF MAX equals MIN then SET VALUE IN COLUMN "MIN" TO 0?

3 REPLIES 3
Super User

## Re: Change Code in AddColumn

you can use if/then/else for it.

#"Substract" = Table.AddColumn(MaxOfYear, "Diferencial aceite", each if [MaxfYear] = [MinOfYear] then [MaxfYear] else [MaxfYear] - [MinOfYear], type number)

Or do I understand you wrong and you expect something like: IF MAX equals MIN then SET VALUE IN COLUMN "MIN" TO 0?

Member

## Re: Change Code in AddColumn

Hello @Nolock that solved my question thank you, now I have to use the same code to substract the production of the last year and the previous year last production like this: 1000 (feb-1-2021) - 700 (april-1-2020) = 300, can you help me ?

 Year Production Diferencial production 2019 300 jan-1-2019 100 feb-1-2019 200 march- 1- 2019 300 Diferencial production 2020 500 april-1-2019 400 jan-1-2020 200 feb-1-2020 300 Diferencial production 2021 300 march- 1- 2020 400 april-1-2020 700 feb-1-2021 1000
Super User

## Re: Change Code in AddColumn

And please try to write more examples that we know what you mean. Thank you very much

Announcements

#### Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

#### Community News & Announcements

Get your latest community news and announcements.

#### Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 393 members 3,663 guests
Recent signins: