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

List how long price was active

Hi All,

 

I have table structure like following:

DateCustomerPrice
1-1-2021AA10
1-2-2021AA10
1-3-2021AA11
1-4-2021AA10
1-5-2021AA10
1-6-2021AA10

and I have to create the following table:

 

CustomerPriceDuration in days
AA102
AA111
AA103

 

Thank you for your help!

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@MrMP 

You can do it in Power Query with a single Group By step. After you group by selecting Customer and Price, add this ", GroupKind.Local" at the end of the group by step.

You can paste the code given below on a Blank Query and check.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ11DUyMDJU0lFydAQShgZKsTogYSPswsaowoZQYRPsqk2xC5thCMcCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Customer = _t, Price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Customer", type text}, {"Price", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Customer", "Price"}, {{"Count", each Table.RowCount(_), Int64.Type}}, GroupKind.Local)
in
    #"Grouped Rows"

 

Fowmy_0-1619463814883.png

 

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
Fowmy
Super User
Super User

@MrMP 

You can do it in Power Query with a single Group By step. After you group by selecting Customer and Price, add this ", GroupKind.Local" at the end of the group by step.

You can paste the code given below on a Blank Query and check.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ11DUyMDJU0lFydAQShgZKsTogYSPswsaowoZQYRPsqk2xC5thCMcCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Customer = _t, Price = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Customer", type text}, {"Price", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Customer", "Price"}, {{"Count", each Table.RowCount(_), Int64.Type}}, GroupKind.Local)
in
    #"Grouped Rows"

 

Fowmy_0-1619463814883.png

 

 

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you.

Is there a chance for this to be dynamic or in dax, since number of dimensions can vary. Sometimes its only a customer, sometimes its customer and product.

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.