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
Anonymous
Not applicable

Derive a Price Type based on Price history

Hey everybody,

Hope to find you well!
Trying to create a new column in the raw data that looks at the Gross Price of a product per specific store.
Anyone recommends a syntax that can do something like the column Type below?

Manu77_0-1656513947746.png

 

 

Thanks and hope you are all well

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hdAxDoAgDIXhuzAzUFowjnICE0fC/a8hxJjgz+Dyhi/0lbRWdx3Ou3NEUtf8ByLh94UYYR4pPWIiZMJGMMJSGgCyP1Def1gkKMEAGgAihLl0WTtCDRCVEAjC0kzoJ2w3", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store Type" = _t, Product = _t, #"Gross Price" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Store Type", "Product"}, {{"Temp", (x)=> Table.AddColumn(x,"Type",each if List.Contains(List.LastN(x[Gross Price],2),[Gross Price]) then "Promo" else "Full Price"), type table}}),
    #"Expanded Temp" = Table.ExpandTableColumn(#"Grouped Rows", "Temp", {"Gross Price", "Type"}, {"Gross Price", "Type"})
in
    #"Expanded Temp"

 

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("hdAxDoAgDIXhuzAzUFowjnICE0fC/a8hxJjgz+Dyhi/0lbRWdx3Ou3NEUtf8ByLh94UYYR4pPWIiZMJGMMJSGgCyP1Def1gkKMEAGgAihLl0WTtCDRCVEAjC0kzoJ2w3", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Store Type" = _t, Product = _t, #"Gross Price" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Store Type", "Product"}, {{"Temp", (x)=> Table.AddColumn(x,"Type",each if List.Contains(List.LastN(x[Gross Price],2),[Gross Price]) then "Promo" else "Full Price"), type table}}),
    #"Expanded Temp" = Table.ExpandTableColumn(#"Grouped Rows", "Temp", {"Gross Price", "Type"}, {"Gross Price", "Type"})
in
    #"Expanded Temp"

 

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