Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Power BI: Create a relative column in power query

lets say I have the following table:

Year Patch Value
2021 1.68 23.5
2021 1.70 25.5
2022 1.75 21.5
2022 1.79 24.5
2023 1.84 25.5
2023 1.89 28.5

I want to create a column with a boolean value "new" and "old" in power query based on the year and the patch version. the smaller patch version in that year should be the old version and higher patch version the new one.

Like getting a result like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Year Patch Value Patch Type
2021 1.68 23.5 old
2021 1.70 25.5 new
2022 1.75 21.5 old
2022 1.79 24.5 new
2023 1.84 25.5 old
2023 1.89 28.5 new

How can I do this in power query?

Thanks!

>Solution :

enter image description here

enter image description here

Add a new column with the following code.

[t=
Table.SelectRows(#"Changed Type", (x)=> x[Year] = [Year]),
min = List.Min(t[Patch]),
max = List.Max(t[Patch]),
result = if [Patch] = min then "old" else if [Patch] = max then "new" else null
][result]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading