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
OscarSuarez10
Helper III
Helper III

Change Code in AddColumn

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
Nolock
Resident Rockstar
Resident Rockstar

Hi @OscarSuarez10,

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?

View solution in original post

3 REPLIES 3
Nolock
Resident Rockstar
Resident Rockstar

Hi @OscarSuarez10,

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?

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 ?

 

YearProduction Diferencial production 2019300
jan-1-2019100 
feb-1-2019200   
march- 1- 2019300 Diferencial production 2020500
april-1-2019400 
jan-1-2020200   
feb-1-2020300 Diferencial production 2021300
march- 1- 2020400 
april-1-2020700   
feb-1-20211000   

Hi @OscarSuarez10,

please create a new thread for a new topic. Especially if this thread is already closed.

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

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